stage3/visit_expression_type.cc
author laurent
Fri, 24 Feb 2012 18:16:56 +0100
changeset 407 2d77f0f77773
parent 406 6381589697ff
permissions -rwxr-xr-x
Fix bug in code generated for MUL function
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     1
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     3
 *
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
     4
 *  Copyright (C) 2009-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: 273
diff changeset
     5
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
     6
 *
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    10
 *  (at your option) any later version.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    11
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    15
 *  GNU General Public License for more details.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    16
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    19
 *
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    20
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    23
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    24
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    25
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 266
diff changeset
    26
 * An IEC 61131-3 compiler.
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    27
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    28
 * Based on the
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    29
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    30
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    31
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    32
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    33
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    34
/* Verify whether the semantic rules of data type compatibility are being followed.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    35
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    36
 * For example:
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    37
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    38
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    39
#include "visit_expression_type.hh"
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    40
#include <typeinfo>
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    41
#include <list>
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    42
#include <string>
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    43
#include <string.h>
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    44
#include <strings.h>
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    45
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    46
287
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
    47
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
9df7fcb9bde5 Added tracking of order by which tokens are processed by lexical analyser.
Mario de Sousa <msousa@fe.up.pt>
parents: 286
diff changeset
    48
#define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    49
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
    50
#define STAGE3_ERROR(symbol1, symbol2, ...) {                                          \
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
    51
    fprintf(stderr, "%s:%d-%d..%d-%d: error : ",                                       \
286
a4f4990d5c66 Adding tracking of filename in which token is located.
Mario de Sousa <msousa@fe.up.pt>
parents: 284
diff changeset
    52
           FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column, \
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
    53
                                                LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column); \
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
    54
    fprintf(stderr, __VA_ARGS__);                                                      \
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
    55
    fprintf(stderr, "\n");                                                             \
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    56
    il_error = true;                                                                   \
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
    57
    error_found = true;                                                                \
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    58
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    59
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    60
259
b6d7c71ff6d8 Adding debug conditional printf()s in stage 3.
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
    61
/* set to 1 to see debug info during execution */
b6d7c71ff6d8 Adding debug conditional printf()s in stage 3.
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
    62
static int debug = 0;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    63
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    64
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    65
void *visit_expression_type_c::visit(program_declaration_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    66
  search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    67
  symbol->var_declarations->accept(*this);
259
b6d7c71ff6d8 Adding debug conditional printf()s in stage 3.
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
    68
  if (debug) printf("checking semantics in body of program %s\n", ((token_c *)(symbol->program_type_name))->value);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    69
  il_parenthesis_level = 0;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    70
  il_error = false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    71
  il_default_variable_type = NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    72
  symbol->function_block_body->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    73
  il_default_variable_type = NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    74
  delete search_varfb_instance_type;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
    75
  search_varfb_instance_type = NULL;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    76
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    77
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    78
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    79
void *visit_expression_type_c::visit(function_declaration_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    80
  search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    81
  symbol->var_declarations_list->accept(*this);
259
b6d7c71ff6d8 Adding debug conditional printf()s in stage 3.
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
    82
  if (debug) printf("checking semantics in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    83
  il_parenthesis_level = 0;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    84
  il_error = false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    85
  il_default_variable_type = NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    86
  symbol->function_body->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    87
  il_default_variable_type = NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    88
  delete search_varfb_instance_type;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
    89
  search_varfb_instance_type = NULL;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    90
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    91
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    92
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    93
void *visit_expression_type_c::visit(function_block_declaration_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    94
  search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    95
  symbol->var_declarations->accept(*this);
259
b6d7c71ff6d8 Adding debug conditional printf()s in stage 3.
Mario de Sousa <msousa@fe.up.pt>
parents: 258
diff changeset
    96
  if (debug) printf("checking semantics in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    97
  il_parenthesis_level = 0;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    98
  il_error = false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
    99
  il_default_variable_type = NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   100
  symbol->fblock_body->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   101
  il_default_variable_type = NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   102
  delete search_varfb_instance_type;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   103
  search_varfb_instance_type = NULL;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   104
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   105
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   106
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   107
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   108
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   109
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   110
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   111
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   112
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   113
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   114
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   115
visit_expression_type_c::visit_expression_type_c(symbol_c *ignore) {
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   116
  error_found = false;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   117
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   118
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   119
visit_expression_type_c::~visit_expression_type_c(void) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   120
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   121
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   122
bool visit_expression_type_c::get_error_found(void) {
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   123
  return error_found;
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   124
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   125
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   126
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   127
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   128
/* NOTE on data type handling and literals...
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   129
 * ==========================================
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   130
 *
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   131
 * Literals that are explicitly type cast 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   132
 *   e.g.:   BYTE#42
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   133
 *           INT#65
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   134
 *           TIME#45h23m
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   135
 *               etc...
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   136
 *  are NOT considered literals in the following code.
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   137
 *  Since they are type cast, and their data type is fixed and well known,
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   138
 *  they are treated as a variable of that data type (except when determining lvalues)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   139
 *  In other words, when calling search_constant_type_c on these constants, it returns
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   140
 *  a xxxxx_type_name_c, and not one of the xxxx_literal_c ! 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   141
 *
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   142
 *  When the following code handles a literal, it is really a literal of unknown data type.
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   143
 *    e.g.   42, may be considered an int, a byte, a word, etc... 
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   144
 *
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   145
 * NOTE: type_symbol == NULL is valid!
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   146
 *       This will occur, for example, when and undefined/undeclared symbolic_variable is used in the program.
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   147
 *       This will not be of any type, so we always return false.
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   148
 */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   149
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   150
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   151
bool visit_expression_type_c::is_ANY_ELEMENTARY_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   152
  if (type_symbol == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   153
  return is_ANY_MAGNITUDE_type(type_symbol)
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   154
      || is_ANY_BIT_type      (type_symbol)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   155
      || is_ANY_STRING_type   (type_symbol)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   156
      || is_ANY_DATE_type     (type_symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   157
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   158
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   159
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   160
bool visit_expression_type_c::is_ANY_SAFEELEMENTARY_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   161
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   162
  return is_ANY_SAFEMAGNITUDE_type(type_symbol)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   163
      || is_ANY_SAFEBIT_type      (type_symbol)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   164
      || is_ANY_SAFESTRING_type   (type_symbol)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   165
      || is_ANY_SAFEDATE_type     (type_symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   166
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   167
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   168
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   169
bool visit_expression_type_c::is_ANY_ELEMENTARY_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   170
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   171
  /* NOTE: doing 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   172
   *          return is_ANY_SAFEELEMENTARY_type() || is_ANY_ELEMENTARY_type()
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   173
   *       is incorrect, as the literals would never be considered compatible...
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   174
   */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   175
  return is_ANY_MAGNITUDE_compatible(type_symbol)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   176
      || is_ANY_BIT_compatible      (type_symbol)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   177
      || is_ANY_STRING_compatible   (type_symbol)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   178
      || is_ANY_DATE_compatible     (type_symbol);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   179
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   180
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   181
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   182
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   183
bool visit_expression_type_c::is_ANY_MAGNITUDE_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   184
  if (type_symbol == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   185
  if (typeid(*type_symbol) == typeid(time_type_name_c)) {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   186
  return is_ANY_NUM_type(type_symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   187
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   188
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   189
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   190
bool visit_expression_type_c::is_ANY_SAFEMAGNITUDE_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   191
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   192
  if (typeid(*type_symbol) == typeid(safetime_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   193
  return is_ANY_SAFENUM_type(type_symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   194
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   195
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   196
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   197
bool visit_expression_type_c::is_ANY_MAGNITUDE_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   198
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   199
  if (is_ANY_MAGNITUDE_type    (type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   200
  if (is_ANY_SAFEMAGNITUDE_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   201
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   202
  return is_ANY_NUM_compatible(type_symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   203
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   205
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   206
bool visit_expression_type_c::is_ANY_NUM_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   207
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   208
  if (is_ANY_REAL_type(type_symbol))                       {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   209
  if (is_ANY_INT_type(type_symbol))                        {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   210
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   211
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   212
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   213
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   214
bool visit_expression_type_c::is_ANY_SAFENUM_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   215
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   216
  return is_ANY_SAFEREAL_type(type_symbol) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   217
      || is_ANY_SAFEINT_type (type_symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   218
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   219
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   220
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   221
bool visit_expression_type_c::is_ANY_NUM_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   222
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   223
  if (is_ANY_REAL_compatible(type_symbol))                       {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   224
  if (is_ANY_INT_compatible(type_symbol))                        {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   225
  return false;  
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   226
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   227
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   228
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   229
bool visit_expression_type_c::is_ANY_DATE_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   230
  if (type_symbol == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   231
  if (typeid(*type_symbol) == typeid(date_type_name_c)) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   232
  if (typeid(*type_symbol) == typeid(tod_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   233
  if (typeid(*type_symbol) == typeid(dt_type_name_c))   {return true;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   234
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   235
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   236
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   237
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   238
bool visit_expression_type_c::is_ANY_SAFEDATE_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   239
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   240
  if (typeid(*type_symbol) == typeid(safedate_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   241
  if (typeid(*type_symbol) == typeid(safetod_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   242
  if (typeid(*type_symbol) == typeid(safedt_type_name_c))   {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   243
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   244
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   245
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   246
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   247
bool visit_expression_type_c::is_ANY_DATE_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   248
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   249
  if (is_ANY_DATE_type    (type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   250
  if (is_ANY_SAFEDATE_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   251
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   252
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   253
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   254
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   255
bool visit_expression_type_c::is_ANY_STRING_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   256
  if (type_symbol == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   257
  if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   258
  if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   259
// TODO literal_string ???
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   260
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   261
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   262
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   263
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   264
bool visit_expression_type_c::is_ANY_SAFESTRING_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   265
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   266
  if (typeid(*type_symbol) == typeid(safestring_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   267
  if (typeid(*type_symbol) == typeid(safewstring_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   268
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   269
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   270
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   271
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   272
bool visit_expression_type_c::is_ANY_STRING_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   273
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   274
  if (is_ANY_STRING_type    (type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   275
  if (is_ANY_SAFESTRING_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   276
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   277
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   278
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   279
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   280
bool visit_expression_type_c::is_ANY_INT_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   281
  if (type_symbol == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   282
  if (typeid(*type_symbol) == typeid(sint_type_name_c))  {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   283
  if (typeid(*type_symbol) == typeid(int_type_name_c))   {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   284
  if (typeid(*type_symbol) == typeid(dint_type_name_c))  {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   285
  if (typeid(*type_symbol) == typeid(lint_type_name_c))  {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   286
  if (typeid(*type_symbol) == typeid(usint_type_name_c)) {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   287
  if (typeid(*type_symbol) == typeid(uint_type_name_c))  {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   288
  if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   289
  if (typeid(*type_symbol) == typeid(ulint_type_name_c)) {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   290
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   291
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   292
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   293
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   294
bool visit_expression_type_c::is_ANY_SAFEINT_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   295
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   296
  if (typeid(*type_symbol) == typeid(safesint_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   297
  if (typeid(*type_symbol) == typeid(safeint_type_name_c))   {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   298
  if (typeid(*type_symbol) == typeid(safedint_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   299
  if (typeid(*type_symbol) == typeid(safelint_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   300
  if (typeid(*type_symbol) == typeid(safeusint_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   301
  if (typeid(*type_symbol) == typeid(safeuint_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   302
  if (typeid(*type_symbol) == typeid(safeudint_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   303
  if (typeid(*type_symbol) == typeid(safeulint_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   304
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   305
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   306
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   307
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   308
bool visit_expression_type_c::is_ANY_INT_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   309
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   310
  if (is_ANY_INT_type    (type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   311
  if (is_ANY_SAFEINT_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   312
  if (is_literal_integer_type(type_symbol))          {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   313
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   314
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   315
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   316
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   317
bool visit_expression_type_c::is_ANY_REAL_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   318
  if (type_symbol == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   319
  if (typeid(*type_symbol) == typeid(real_type_name_c))  {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   320
  if (typeid(*type_symbol) == typeid(lreal_type_name_c)) {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   321
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   322
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   323
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   324
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   325
bool visit_expression_type_c::is_ANY_SAFEREAL_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   326
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   327
  if (typeid(*type_symbol) == typeid(safereal_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   328
  if (typeid(*type_symbol) == typeid(safelreal_type_name_c)) {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   329
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   330
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   331
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   332
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   333
bool visit_expression_type_c::is_ANY_REAL_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   334
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   335
  if (is_ANY_REAL_type    (type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   336
  if (is_ANY_SAFEREAL_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   337
  if (is_literal_real_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   338
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   339
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   340
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   341
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   342
bool visit_expression_type_c::is_ANY_BIT_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   343
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   344
  if (typeid(*type_symbol) == typeid(bool_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   345
  if (typeid(*type_symbol) == typeid(byte_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   346
  if (typeid(*type_symbol) == typeid(word_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   347
  if (typeid(*type_symbol) == typeid(dword_type_name_c))    {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   348
  if (typeid(*type_symbol) == typeid(lword_type_name_c))    {return true;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   349
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   350
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   351
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   352
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   353
bool visit_expression_type_c::is_ANY_SAFEBIT_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   354
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   355
  if (typeid(*type_symbol) == typeid(safebool_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   356
  if (typeid(*type_symbol) == typeid(safebyte_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   357
  if (typeid(*type_symbol) == typeid(safeword_type_name_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   358
  if (typeid(*type_symbol) == typeid(safedword_type_name_c))    {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   359
  if (typeid(*type_symbol) == typeid(safelword_type_name_c))    {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   360
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   361
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   362
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   363
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   364
bool visit_expression_type_c::is_ANY_BIT_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   365
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   366
  if (is_ANY_BIT_type    (type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   367
  if (is_ANY_SAFEBIT_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   368
  if (is_nonneg_literal_integer_type(type_symbol))   {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   369
  if (is_literal_bool_type(type_symbol))             {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   370
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   371
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   372
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   373
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   374
bool visit_expression_type_c::is_BOOL_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   375
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   376
  if (typeid(*type_symbol) == typeid(bool_type_name_c))      {return true;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   377
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   378
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   379
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   380
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   381
bool visit_expression_type_c::is_SAFEBOOL_type(symbol_c *type_symbol){
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   382
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   383
  if (typeid(*type_symbol) == typeid(safebool_type_name_c))  {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   384
  return false;  
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   385
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   386
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   387
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   388
bool visit_expression_type_c::is_ANY_BOOL_compatible(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   389
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   390
  if (is_BOOL_type    (type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   391
  if (is_SAFEBOOL_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   392
  if (is_literal_bool_type(type_symbol))              {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   393
  return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   394
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   395
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   396
333
b495a49f5038 Fix bug when trying to find the type of a NULL symbol
laurent
parents: 331
diff changeset
   397
#define is_type(type_name_symbol, type_name_class)  ((type_name_symbol == NULL) ? false : (typeid(*type_name_symbol) == typeid(type_name_class)))
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   398
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   399
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   400
#define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   401
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   402
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   403
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   404
bool visit_expression_type_c::is_literal_integer_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   405
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   406
  if (typeid(*type_symbol) == typeid(neg_integer_c))        {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   407
  return is_nonneg_literal_integer_type(type_symbol);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   408
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   409
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   410
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   411
/* A helper function... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   412
bool visit_expression_type_c::is_nonneg_literal_integer_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   413
  if (type_symbol == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   414
  if (typeid(*type_symbol) == typeid(integer_c))        {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   415
  if (typeid(*type_symbol) == typeid(binary_integer_c)) {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   416
  if (typeid(*type_symbol) == typeid(octal_integer_c))  {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   417
  if (typeid(*type_symbol) == typeid(hex_integer_c))    {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   418
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   419
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   420
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   421
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   422
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   423
bool visit_expression_type_c::is_literal_real_type(symbol_c *type_symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   424
  if (type_symbol == NULL) {return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   425
  if (typeid(*type_symbol) == typeid(real_c))     {return true;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   426
  if (typeid(*type_symbol) == typeid(neg_real_c)) {return true;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   427
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   428
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   429
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   430
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   431
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   432
bool visit_expression_type_c::is_literal_bool_type(symbol_c *type_symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   433
  bool_type_name_c bool_t;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   434
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   435
  if (type_symbol == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   436
  if (typeid(*type_symbol) == typeid(boolean_true_c))    {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   437
  if (typeid(*type_symbol) == typeid(boolean_false_c))   {return true;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   438
  if (is_nonneg_literal_integer_type(type_symbol))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   439
    if (sizeoftype(&bool_t) >= sizeoftype(type_symbol))  {return true;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   440
  return false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   441
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   442
390
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
   443
bool visit_expression_type_c::is_ANY_ELEMENTARY_OR_ENUMERATED_compatible(symbol_c *type_symbol) {
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
   444
  if (type_symbol == NULL) {return false;}
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
   445
  if (search_base_type.type_is_enumerated(type_symbol)) {return true;}
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
   446
  return is_ANY_ELEMENTARY_compatible(type_symbol);
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
   447
}
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
   448
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
   449
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   450
/* Determine the common data type between two data types.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   451
 * If no common data type found, return NULL.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   452
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   453
 * If data types are identical, return the first (actually any would do...).
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   454
 * If any of the data types is a literal, we confirm that 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   455
 *   the literal uses less bits than the fixed size data type.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   456
 *   e.g. BYTE and 1024 returns NULL
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   457
 *        BYTE and 255  returns BYTE
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   458
 *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   459
 * If two literals, then return the literal that requires more bits...
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   460
 */
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   461
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   462
symbol_c *visit_expression_type_c::common_type__(symbol_c *first_type, symbol_c *second_type) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   463
  if (first_type == NULL && second_type == NULL) {return NULL;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   464
  if (first_type == NULL)  {return second_type;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   465
  if (second_type == NULL) {return first_type;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   466
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   467
  if (is_literal_integer_type(first_type) && is_literal_integer_type(second_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   468
    {return ((sizeoftype(first_type) > sizeoftype(second_type))? first_type:second_type);}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   469
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   470
  if (is_literal_real_type(first_type) && is_literal_real_type(second_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   471
    {return ((sizeoftype(first_type) > sizeoftype(second_type))? first_type:second_type);}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   472
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   473
  if (is_literal_bool_type(first_type) && is_literal_bool_type(second_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   474
    {return first_type;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   475
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   476
  /* The following check can only be made after the is_literal_XXXX checks */
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   477
  /* When two literals of the same type, with identical typeid's are checked,
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   478
   * we must return the one that occupies more bits... This is done above.
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   479
   */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   480
  if (typeid(*first_type) == typeid(*second_type)) {return first_type;}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   481
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   482
  /* NOTE Although a BOOL is also an ANY_BIT, we must check it explicitly since some
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   483
   *       literal bool values are not literal integers...
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   484
   */ 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   485
  if (is_BOOL_type(first_type)        && is_literal_bool_type(second_type))    {return first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   486
  if (is_BOOL_type(second_type)       && is_literal_bool_type(first_type))     {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   487
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   488
  if (is_SAFEBOOL_type(first_type)    && is_literal_bool_type(second_type))    {return first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   489
  if (is_SAFEBOOL_type(second_type)   && is_literal_bool_type(first_type))     {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   490
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   491
  if (is_SAFEBOOL_type(first_type)    && is_BOOL_type(second_type))            {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   492
  if (is_SAFEBOOL_type(second_type)   && is_BOOL_type(first_type))             {return first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   493
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   494
  if (is_ANY_BIT_type(first_type)     && is_nonneg_literal_integer_type(second_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   495
    {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   496
  if (is_ANY_BIT_type(second_type)    && is_nonneg_literal_integer_type(first_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   497
    {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   498
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   499
  if (is_ANY_SAFEBIT_type(first_type)     && is_nonneg_literal_integer_type(second_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   500
    {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   501
  if (is_ANY_SAFEBIT_type(second_type)    && is_nonneg_literal_integer_type(first_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   502
    {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   503
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   504
  if  (is_ANY_SAFEBIT_type(first_type)    && is_ANY_BIT_type(second_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   505
    {return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   506
  if  (is_ANY_SAFEBIT_type(second_type)   && is_ANY_BIT_type(first_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   507
    {return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   508
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   509
  if (is_ANY_INT_type(first_type)     && is_literal_integer_type(second_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   510
    {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   511
  if (is_ANY_INT_type(second_type)    && is_literal_integer_type(first_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   512
    {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   513
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   514
  if (is_ANY_SAFEINT_type(first_type)     && is_literal_integer_type(second_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   515
    {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   516
  if (is_ANY_SAFEINT_type(second_type)    && is_literal_integer_type(first_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   517
    {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   518
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   519
  if  (is_ANY_SAFEINT_type(first_type)    && is_ANY_INT_type(second_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   520
    {return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   521
  if  (is_ANY_SAFEINT_type(second_type)   && is_ANY_INT_type(first_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   522
    {return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   523
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   524
  if (is_ANY_REAL_type(first_type)    && is_literal_real_type(second_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   525
    {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   526
  if (is_ANY_REAL_type(second_type)   && is_literal_real_type(first_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   527
    {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   528
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   529
  if (is_ANY_SAFEREAL_type(first_type)    && is_literal_real_type(second_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   530
    {return ((sizeoftype(first_type)  >= sizeoftype(second_type))? first_type :NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   531
  if (is_ANY_SAFEREAL_type(second_type)   && is_literal_real_type(first_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   532
    {return ((sizeoftype(second_type) >= sizeoftype(first_type)) ? second_type:NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   533
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   534
  if  (is_ANY_SAFEREAL_type(first_type)    && is_ANY_REAL_type(second_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   535
    {return ((sizeoftype(first_type) == sizeoftype(second_type))? second_type:NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   536
  if  (is_ANY_SAFEREAL_type(second_type)   && is_ANY_REAL_type(first_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   537
    {return ((sizeoftype(first_type) == sizeoftype(second_type))? first_type :NULL);}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   538
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   539
  /* the Time and Date types... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   540
  if (is_type(first_type,  safetime_type_name_c) && is_type(second_type, time_type_name_c))  {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   541
  if (is_type(second_type, safetime_type_name_c) && is_type( first_type, time_type_name_c))  {return  first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   542
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   543
  if (is_type(first_type,  safedate_type_name_c) && is_type(second_type, date_type_name_c))  {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   544
  if (is_type(second_type, safedate_type_name_c) && is_type( first_type, date_type_name_c))  {return  first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   545
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   546
  if (is_type(first_type,  safedt_type_name_c)   && is_type(second_type, dt_type_name_c))    {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   547
  if (is_type(second_type, safedt_type_name_c)   && is_type( first_type, dt_type_name_c))    {return  first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   548
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   549
  if (is_type(first_type,  safetod_type_name_c)  && is_type(second_type, tod_type_name_c))   {return second_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   550
  if (is_type(second_type, safetod_type_name_c)  && is_type( first_type, tod_type_name_c))   {return  first_type;}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   551
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   552
  /* no common type */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   553
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   554
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   555
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   556
/* Determine the common data type between two data types.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   557
 * Unlike the common_type__() function, we stop the compiler with an ERROR
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   558
 *  if no common data type is found.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   559
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   560
symbol_c *visit_expression_type_c::common_type(symbol_c *first_type, symbol_c *second_type) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   561
/*  
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   562
  symbol_c *res = common_type__(first_type, second_type);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   563
  if (NULL == res) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   564
  return res;
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   565
*/
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   566
  return common_type__(first_type, second_type);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   567
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   568
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   569
symbol_c *visit_expression_type_c::common_literal(symbol_c *first_type, symbol_c *second_type) {
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   570
  printf("common_literal: %d == %d, %d == %d, %d == %d\n",
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   571
		 (int)is_ANY_INT_compatible(first_type),
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   572
		 (int)is_ANY_INT_compatible(second_type),
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   573
		 (int)is_ANY_REAL_compatible(first_type),
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   574
		 (int)is_ANY_REAL_compatible(second_type),
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   575
		 (int)is_ANY_BIT_compatible(first_type),
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   576
		 (int)is_ANY_BIT_compatible(second_type));
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   577
  if ((is_ANY_INT_compatible(first_type) && is_ANY_INT_compatible(second_type)) ||
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   578
	  (is_ANY_BIT_compatible(first_type) && is_ANY_BIT_compatible(second_type)))
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   579
	 return &search_constant_type_c::integer;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   580
  else if (is_ANY_REAL_compatible(first_type) && is_ANY_REAL_compatible(second_type))
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   581
	 return &search_constant_type_c::real;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   582
  return NULL;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   583
}
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   584
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   585
symbol_c *visit_expression_type_c::overloaded_return_type(symbol_c *type) {
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   586
  if (is_ANY_INT_compatible(type))
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
   587
    return &search_constant_type_c::ulint_type_name;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   588
  else if (is_ANY_REAL_compatible(type))
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
   589
    return &search_constant_type_c::lreal_type_name;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   590
  else if (is_ANY_BIT_compatible(type))
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
   591
      return &search_constant_type_c::lword_type_name;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   592
  return NULL;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
   593
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   594
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   595
/* Return TRUE if the second (value) data type may be assigned to a variable of the first (variable) data type
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   596
 * such as: 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   597
 *     var_type     value_type
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   598
 *    BOOL           BYTE#7     -> returns false
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   599
 *    INT            INT#7      -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   600
 *    INT            7          -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   601
 *    REAL           7.89       -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   602
 *    REAL           7          -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   603
 *    INT            7.89       -> returns false
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   604
 *    SAFEBOOL       BOOL#1     -> returns false   !!!
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   605
 *   etc...
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   606
 *
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   607
 * NOTE: It is assumed that the var_type is the data type of an lvalue
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   608
 */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   609
bool visit_expression_type_c::is_valid_assignment(symbol_c *var_type, symbol_c *value_type) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   610
  if (var_type == NULL)   {/* STAGE3_ERROR(value_type, value_type, "Var_type   == NULL"); */ return false;}
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   611
  if (value_type == NULL) {/* STAGE3_ERROR(var_type,   var_type,   "Value_type == NULL"); */ return false;}
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   612
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   613
  symbol_c *common_type = common_type__(var_type, value_type);
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   614
  if (NULL == common_type)
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   615
    return false;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   616
  return (typeid(*var_type) == typeid(*common_type));
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   617
}
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   618
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   619
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   620
/* Return TRUE if there is a common data type, otherwise return FALSE
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   621
 * i.e., return TRUE if both data types may be used simultaneously in an expression
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   622
 * such as:
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   623
 *    BOOL#0     AND BYTE#7  -> returns false
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   624
 *    0          AND BYTE#7  -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   625
 *    INT#10     AND INT#7   -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   626
 *    INT#10     AND 7       -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   627
 *    REAL#34.3  AND 7.89    -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   628
 *    REAL#34.3  AND 7       -> returns true
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   629
 *    INT#10     AND 7.89    -> returns false
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   630
 *    SAFEBOOL#0 AND BOOL#1  -> returns true   !!!
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   631
 *   etc...
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   632
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   633
bool visit_expression_type_c::is_compatible_type(symbol_c *first_type, symbol_c *second_type) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   634
  if (first_type == NULL || second_type == NULL) {return false;}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   635
  return (NULL != common_type__(first_type, second_type));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   636
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   637
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   638
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   639
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   640
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   641
/* A helper function... */
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   642
/*
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   643
symbol_c *visit_expression_type_c::compute_boolean_expression(symbol_c *left_type, symbol_c *right_type,
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   644
                                                              is_data_type_t is_data_type) {
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
   645
*/
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   646
symbol_c *visit_expression_type_c::compute_expression(symbol_c *left_type,      symbol_c *right_type,     is_data_type_t is_data_type,
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   647
						      symbol_c *left_expr, symbol_c *right_expr) {
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   648
  bool error = false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   649
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   650
  if (!(this->*is_data_type)(left_type)) {
263
bcb92f5b9a91 Adding some debug info
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
   651
    if (debug) printf("visit_expression_type_c::compute_expression(): invalid left_type\n");
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   652
    if (left_expr != NULL)
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
   653
      STAGE3_ERROR(left_expr, left_expr, "Invalid data type of operand, or of data resulting from previous IL instructions.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   654
    error = true;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   655
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   656
  if (!(this->*is_data_type)(right_type)) {
263
bcb92f5b9a91 Adding some debug info
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
   657
    if (debug) printf("visit_expression_type_c::compute_expression(): invalid right_type\n");
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   658
    if (right_expr != NULL)
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
   659
      STAGE3_ERROR(right_expr, right_expr, "Invalid data type of operand.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   660
    error = true;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   661
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   662
  if (!is_compatible_type(left_type, right_type)) {
263
bcb92f5b9a91 Adding some debug info
Mario de Sousa <msousa@fe.up.pt>
parents: 262
diff changeset
   663
    if (debug) printf("visit_expression_type_c::compute_expression(): left_type & right_type are incompatible\n");
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   664
    if ((left_expr != NULL) && (right_expr != NULL))
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   665
      STAGE3_ERROR(left_expr, right_expr, "Type mismatch between operands.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   666
    error = true;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   667
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   668
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   669
  if (error)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   670
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   671
  else
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   672
    return common_type(left_type, right_type);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   673
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   674
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   675
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   676
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   677
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   678
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   679
/* check the semantics of a FB or Function non-formal call */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   680
/* e.g. foo(1, 2, 3, 4);  */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   681
/* If error_count pointer is != NULL, we do not really print out the errors,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   682
 * but rather only count how many errors were found.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   683
 * This is used to support overloaded functions, where we have to check each possible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   684
 * function, one at a time, untill we find a function call without any errors.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   685
 */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   686
void visit_expression_type_c::check_nonformal_call(symbol_c *f_call, symbol_c *f_decl, bool use_il_defvar, int *error_count) {
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   687
  symbol_c *call_param_value, *call_param_type, *param_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   688
  identifier_c *param_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   689
  function_param_iterator_c       fp_iterator(f_decl);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   690
  function_call_param_iterator_c fcp_iterator(f_call);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   691
  int extensible_parameter_highest_index = -1;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   692
  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   693
  /* reset error counter */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   694
  if (error_count != NULL) *error_count = 0;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   695
  /* if use_il_defvar, then the first parameter for the call comes from the il_default_variable */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   696
  if (use_il_defvar) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   697
    /* The first parameter of the function corresponds to the il_default_variable_type of the function call */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   698
    do {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   699
      param_name = fp_iterator.next();
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   700
      if(param_name == NULL) break;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   701
      /*  The EN and ENO parameters are default parameters.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   702
       *  In the non-formal invocation of a function there can be no assignment of
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   703
       * values to these parameters. Therefore, we ignore the parameters declared
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   704
       * in the function.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   705
       */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   706
    } while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   707
    /* If the function does not have any parameters (param_name == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   708
     * then we cannot compare its type with the il_default_variable_type.
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   709
     *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   710
     * However, I (Mario) think this is invalid syntax, as it seems to me all functions must
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   711
     * have at least one parameter.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   712
     * However, we will make this semantic verification consider it possible, as later
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   713
     * versions of the standard may change that syntax.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   714
     * So, instead of generating a syntax error message, we simply check whether the call
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   715
     * is passing any more parameters besides the default variable (the il default variable may be ignored
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   716
     * in this case, and not consider it as being a parameter being passed to the function).
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   717
     * If it does, then we have found a semantic error, otherwise the function call is 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   718
     * correct, and we simply return.
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   719
     */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   720
    if(param_name == NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   721
      if (fcp_iterator.next_nf() != NULL)
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   722
        STAGE3_ERROR(f_call, f_call, "Too many parameters in function/FB call.");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   723
      return;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   724
    } else { 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   725
      /* param_name != NULL */
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   726
      param_type = fp_iterator.param_type();
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   727
      if(!is_valid_assignment(param_type, il_default_variable_type)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   728
        if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   729
        else STAGE3_ERROR(f_call, f_call, "In function/FB call, first parameter has invalid data type.");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   730
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   731
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   732
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   733
    /* the fisrt parameter (il_def_variable) is correct */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   734
    if (extensible_parameter_highest_index < fp_iterator.extensible_param_index()) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   735
      extensible_parameter_highest_index = fp_iterator.extensible_param_index();
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   736
    }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   737
  } // if (use_il_defvar)
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   738
  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   739
  
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   740
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   741
  /* Iterating through the non-formal parameters of the function call */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   742
  while((call_param_value = fcp_iterator.next_nf()) != NULL) {
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   743
    /* Obtaining the type of the value being passed in the function call */
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   744
    call_param_type = base_type((symbol_c*)call_param_value->accept(*this));
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   745
    if (call_param_type == NULL) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   746
      if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   747
      /* the following error will usually occur when ST code uses an identifier, that could refer to an enumerated constant,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   748
       * but was not actually used as a constant in any definitions of an enumerated data type
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   749
       */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   750
      else STAGE3_ERROR(call_param_value, call_param_value, "Could not determine data type of value being passed in function/FB call.");
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   751
      continue;
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   752
    }  
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   753
    
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   754
    /* Iterate to the next parameter of the function being called.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   755
     * Get the name of that parameter, and ignore if EN or ENO.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   756
     */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   757
    do {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   758
      param_name = fp_iterator.next();
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   759
      /* If there is no other parameter declared, then we are passing too many parameters... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   760
      if(param_name == NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   761
        if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   762
        /* Note: We don't want to print out the follwoing error message multiple times, so we return instead of continuing with 'break' */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   763
        else STAGE3_ERROR(f_call, f_call, "Too many parameters in function/FB call."); return;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   764
      }
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   765
    } while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 0));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   766
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   767
    /* Get the parameter type */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   768
    param_type = base_type(fp_iterator.param_type());
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   769
    /* If the declared parameter and the parameter from the function call do not have the same type */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   770
    if(!is_valid_assignment(param_type, call_param_type)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   771
      if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   772
      else STAGE3_ERROR(call_param_value, call_param_value, "Type mismatch in function/FB call parameter.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   773
    }
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   774
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   775
    if (extensible_parameter_highest_index < fp_iterator.extensible_param_index()) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   776
      extensible_parameter_highest_index = fp_iterator.extensible_param_index();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   777
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   778
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   779
  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   780
  /* The function call may not have any errors! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   781
  /* In the case of a call to an extensible function, we store the highest index 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   782
   * of the extensible parameters this particular call uses, in the symbol_c object
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   783
   * of the function call itself!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   784
   * In calls to non-extensible functions, this value will be set to -1.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   785
   * This information is later used in stage4 to correctly generate the
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   786
   * output code.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   787
   */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   788
  int extensible_param_count = -1;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   789
  if (extensible_parameter_highest_index >=0) /* if call to extensible function */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   790
    extensible_param_count = 1 + extensible_parameter_highest_index - fp_iterator.first_extensible_param_index();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   791
  il_function_call_c     *il_function_call = dynamic_cast<il_function_call_c *>(f_call);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   792
  function_invocation_c  *function_invocation  = dynamic_cast<function_invocation_c  *>(f_call);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   793
  if      (il_function_call     != NULL) il_function_call   ->extensible_param_count = extensible_param_count;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   794
  else if (function_invocation  != NULL) function_invocation->extensible_param_count = extensible_param_count;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   795
  //   else ERROR;  /* this function is also called by Function Blocks, so this is not an error! */
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   796
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   797
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   798
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   799
/* check semantics of FB call in the IL language using input operators */
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   800
/* e.g. CU, CLK, IN, PT, SR, ...                                       */
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   801
void visit_expression_type_c::check_il_fbcall(symbol_c *il_operator, const char *il_operator_str) {
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   802
  symbol_c *call_param_type = il_default_variable_type;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   803
  symbol_c *fb_decl = il_operand_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   804
    /* The following should never occur. The function block must be defined, 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   805
     * and the FB type being called MUST be in the symtable... 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   806
     * This was all already checked at stage 2!
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   807
     */
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   808
  if (NULL == fb_decl) ERROR;
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   809
  if (call_param_type == NULL) ERROR;
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   810
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   811
  /* We also create an identifier_c object, so we can later use it to find the equivalent FB parameter */
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   812
  /* Note however that this symbol does not have the correct location (file name and line numbers) 
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   813
   * so any error messages must use the il_operator symbol to generate the error location
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   814
   */
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   815
  identifier_c call_param_name(il_operator_str);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   816
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   817
  /* Obtaining the type of the value being passed in the function call */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   818
  call_param_type = base_type(call_param_type);
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   819
  if (call_param_type == NULL) STAGE3_ERROR(il_operator, il_operator, "Could not determine data type of value being passed in FB call.");
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   820
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   821
  /* Find the corresponding parameter of the function being called */
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   822
  function_param_iterator_c fp_iterator(fb_decl);
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   823
  if(fp_iterator.search(&call_param_name) == NULL) {
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   824
    STAGE3_ERROR(il_operand, il_operand, "Called FB does not have an input parameter named %s.", il_operator_str);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   825
  } else {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   826
    /* Get the parameter type */
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   827
    symbol_c *param_type = base_type(fp_iterator.param_type());
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   828
    /* If the declared parameter and the parameter from the function call have the same type */
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   829
    if(!is_valid_assignment(param_type, call_param_type)) STAGE3_ERROR(il_operator, il_operator, "Type mismatch in FB call parameter.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   830
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   831
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   832
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   833
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   834
/* A helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   835
/* check the semantics of a FB or Function formal call */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   836
/* e.g. foo(IN1 := 1, OUT1 =>x, EN := true);  */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   837
/* If error_count pointer is != NULL, we do not really print out the errors,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   838
 * but rather only count how many errors were found.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   839
 * This is used to support overloaded functions, where we have to check each possible
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   840
 * function, one at a time, untill we find a function call without any errors.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   841
 */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   842
void visit_expression_type_c::check_formal_call(symbol_c *f_call, symbol_c *f_decl, int *error_count) {
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   843
  symbol_c *call_param_value, *call_param_type, *call_param_name, *param_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   844
  symbol_c *verify_duplicate_param;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   845
  identifier_c *param_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   846
  function_param_iterator_c       fp_iterator(f_decl);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   847
  function_call_param_iterator_c fcp_iterator(f_call);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   848
  int extensible_parameter_highest_index = -1;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   849
  identifier_c *extensible_parameter_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   850
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   851
  /* reset error counter */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   852
  if (error_count != NULL) *error_count = 0;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   853
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   854
  /* Iterating through the formal parameters of the function call */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   855
  while((call_param_name = fcp_iterator.next_f()) != NULL) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   856
        
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   857
    /* Obtaining the value being passed in the function call */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   858
    call_param_value = fcp_iterator.get_current_value();
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   859
    /* the following should never occur. If it does, then we have a bug in our code... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   860
    if (NULL == call_param_value) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   861
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   862
    /* Checking if there are duplicated parameter values */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   863
    verify_duplicate_param = fcp_iterator.search_f(call_param_name);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   864
    if(verify_duplicate_param != call_param_value){
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   865
      if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   866
      else STAGE3_ERROR(call_param_name, verify_duplicate_param, "Duplicated parameter values.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   867
    }   
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   868
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   869
    /* Obtaining the type of the value being passed in the function call */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   870
    call_param_type = (symbol_c*)call_param_value->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   871
    if (call_param_type == NULL) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   872
      if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   873
      else STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   874
      /* The data value being passed is possibly any enumerated type value.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   875
       * We do not yet handle semantic verification of enumerated types.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   876
       */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   877
      ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   878
    }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   879
    call_param_type = base_type(call_param_type);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   880
    if (call_param_type == NULL) STAGE3_ERROR(call_param_name, call_param_value, "Could not determine data type of value being passed in function/FB call.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   881
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   882
    /* Find the corresponding parameter of the function being called */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   883
    param_name = fp_iterator.search(call_param_name);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   884
    if(param_name == NULL) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   885
      if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   886
      else STAGE3_ERROR(call_param_name, call_param_name, "Invalid parameter in function/FB call.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   887
    } else {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   888
      /* Get the parameter type */
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   889
      param_type = base_type(fp_iterator.param_type());
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   890
      /* If the declared parameter and the parameter from the function call have the same type */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   891
      if(!is_valid_assignment(param_type, call_param_type)) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   892
        if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   893
        else STAGE3_ERROR(call_param_name, call_param_value, "Type mismatch function/FB call parameter.");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   894
      }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   895
      if (extensible_parameter_highest_index < fp_iterator.extensible_param_index()) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   896
        extensible_parameter_highest_index = fp_iterator.extensible_param_index();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   897
        extensible_parameter_name = param_name;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   898
      }
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   899
    }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   900
  }
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   901
  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   902
  /* In the case of a call to an extensible function, we store the highest index 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   903
   * of the extensible parameters this particular call uses, in the symbol_c object
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   904
   * of the function call itself!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   905
   * In calls to non-extensible functions, this value will be set to -1.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   906
   * This information is later used in stage4 to correctly generate the
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   907
   * output code.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   908
   */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   909
  int extensible_param_count = -1;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   910
  if (extensible_parameter_highest_index >=0) /* if call to extensible function */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   911
    extensible_param_count = 1 + extensible_parameter_highest_index - fp_iterator.first_extensible_param_index();
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   912
  il_formal_funct_call_c *il_formal_funct_call = dynamic_cast<il_formal_funct_call_c *>(f_call);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   913
  function_invocation_c  *function_invocation  = dynamic_cast<function_invocation_c  *>(f_call);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   914
  if      (il_formal_funct_call != NULL) il_formal_funct_call->extensible_param_count = extensible_param_count;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   915
  else if (function_invocation  != NULL) function_invocation->extensible_param_count  = extensible_param_count;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   916
//   else ERROR;  /* this function is also called by Function Blocks, so this is not an error! */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   917
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   918
  /* We have iterated through all the formal parameters of the function call,
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   919
   * and everything seems fine. 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   920
   * If the function being called in an extensible function, we now check
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   921
   * whether the extensible paramters in the formal invocation do not skip
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   922
   * any indexes...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   923
   *
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   924
   * f(in1:=0, in2:=0, in4:=0) --> ERROR!!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   925
   */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   926
  if (extensible_parameter_highest_index >=0) { /* if call to extensible function */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   927
    for (int i=fp_iterator.first_extensible_param_index(); i < extensible_parameter_highest_index; i++) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   928
      char tmp[256];
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   929
      if (snprintf(tmp, 256, "%s%d", extensible_parameter_name->value, i) >= 256) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   930
      if (fcp_iterator.search_f(tmp) == NULL) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   931
        /* error in invocation of extensible function */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   932
        if (error_count != NULL) (*error_count)++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   933
        else STAGE3_ERROR(f_call, f_call, "Missing extensible parameters in call to extensible function.");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   934
      }  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   935
    }    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
   936
  }  
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   937
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   938
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   939
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   940
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   941
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   942
/* a helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   943
symbol_c *visit_expression_type_c::base_type(symbol_c *symbol) {
262
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   944
  /* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   945
   *       in the code.
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   946
   */
197ba42d78b2 Do not crash when checking semantics of undeclared symbolic_variable.
Mario de Sousa <msousa@fe.up.pt>
parents: 260
diff changeset
   947
  if (symbol == NULL) return NULL;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   948
  return (symbol_c *)symbol->accept(search_base_type);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   949
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   950
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   951
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   952
/* a helper function... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   953
void *visit_expression_type_c::verify_null(symbol_c *symbol){
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   954
  if(il_default_variable_type == NULL){
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
   955
    STAGE3_ERROR(symbol, symbol, "Missing LD instruction (or equivalent) before this instruction.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   956
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   957
  if(il_operand_type == NULL){
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
   958
    STAGE3_ERROR(symbol, symbol, "This instruction requires an operand.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   959
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   960
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   961
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   962
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   963
305
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
   964
/********************************/
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
   965
/* B 1.3.3 - Derived data types */
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
   966
/********************************/
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
   967
void *visit_expression_type_c::visit(data_type_declaration_c *symbol) {
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
   968
  // TODO !!!
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
   969
  /* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
   970
  return NULL;
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
   971
}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   972
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   973
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   974
/*********************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   975
/* B 1.4 - Variables */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   976
/*********************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   977
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   978
void *visit_expression_type_c::visit(symbolic_variable_c *symbol) {
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
   979
  return search_varfb_instance_type->get_basetype_decl(symbol);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   980
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   981
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   982
/********************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   983
/* B 1.4.1 - Directly Represented Variables */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   984
/********************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   985
void *visit_expression_type_c::visit(direct_variable_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   986
  switch (symbol->value[2]) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   987
    case 'X': // bit - 1 bit
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   988
      return (void *)&bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   989
    case 'B': // byte - 8 bits
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   990
      return (void *)&byte_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   991
    case 'W': // word - 16 bits
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   992
      return (void *)&word_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   993
    case 'D': // double word - 32 bits
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   994
      return (void *)&dword_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   995
    case 'L': // long word - 64 bits
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   996
      return (void *)&lword_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   997
    default:  // if none of the above, then the empty string was used <=> boolean 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   998
      return (void *)&bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
   999
   }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1000
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1001
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1002
/*************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1003
/* B 1.4.2 - Multi-element variables */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1004
/*************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1005
void *visit_expression_type_c::visit(array_variable_c *symbol) {
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1006
  return search_varfb_instance_type->get_basetype_decl(symbol);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1007
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1008
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1009
void *visit_expression_type_c::visit(structured_variable_c *symbol) {
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1010
  return search_varfb_instance_type->get_basetype_decl(symbol);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1011
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1012
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1013
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1014
319
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1015
/********************************/
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1016
/* B 1.7 Configuration elements */
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1017
/********************************/
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1018
void *visit_expression_type_c::visit(configuration_declaration_c *symbol) {
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1019
  // TODO !!!
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1020
  /* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1021
  return NULL;
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1022
}
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1023
1669977e84f4 Skip CONFIGURATION declarations in stage 3 for now, so semantic analysis does not stop when a configuration is encountered.
Mario de Sousa <msousa@fe.up.pt>
parents: 305
diff changeset
  1024
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1025
/****************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1026
/* B.2 - Language IL (Instruction List) */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1027
/****************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1028
/***********************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1029
/* B 2.1 Instructions and Operands */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1030
/***********************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1031
/*| instruction_list il_instruction */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1032
/* The visitor of the base class search_visitor_c will handle calling each instruction in the list.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1033
 * We do not need to do anything here...
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1034
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1035
// void *visit_expression_type_c::visit(instruction_list_c *symbol)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1036
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1037
/* | label ':' [il_incomplete_instruction] eol_list */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1038
//SYM_REF2(il_instruction_c, label, il_instruction)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1039
// void *visit_expression_type_c::visit(il_instruction_c *symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1040
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1041
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1042
/* | il_simple_operator [il_operand] */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1043
// SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1044
void *visit_expression_type_c::visit(il_simple_operation_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1045
  if (il_error)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1046
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1047
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1048
  /* determine the data type of the operand */
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1049
  il_operand = symbol->il_operand;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1050
  if (symbol->il_operand != NULL){
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1051
    il_operand_type = base_type((symbol_c *)symbol->il_operand->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1052
  } else {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1053
    il_operand_type = NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1054
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1055
  /* recursive call to see whether data types are compatible */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1056
  symbol->il_simple_operator->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1057
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1058
  il_operand_type = NULL;
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1059
  il_operand = NULL;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1060
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1061
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1062
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1063
// | function_name [il_operand_list] */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1064
//SYM_REF2(il_function_call_c, function_name, il_operand_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1065
void *visit_expression_type_c::visit(il_function_call_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1066
  if (il_error)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1067
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1068
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1069
  symbol_c *return_data_type = NULL;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1070
  symbol_c* fdecl_return_type;
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1071
  symbol_c* overloaded_data_type = NULL;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1072
  int extensible_param_count = -1;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1073
  symbol->called_function_declaration = NULL;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1074
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1075
  /* First find the declaration of the function being called! */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1076
  function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1077
  function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name);
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1078
  function_symtable_t::iterator current;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1079
  if (lower == function_symtable.end()) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1080
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1081
  int error_count = 0; 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1082
  int *error_count_ptr = NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1083
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1084
  function_symtable_t::iterator second = lower;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1085
  second++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1086
  if (second != upper) 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1087
    /* This is a call to an overloaded function... */  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1088
    error_count_ptr = &error_count;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1089
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1090
  for(current = lower; current != upper; current++) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1091
    function_declaration_c *f_decl = function_symtable.get_value(current);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1092
    
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1093
    check_nonformal_call(symbol, f_decl, true, error_count_ptr);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1094
    
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1095
    if (0 == error_count) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1096
      /* Either: 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1097
       * (i) we have a call to a non-overloaded function (error_cnt_ptr is NULL!, so error_count won't change!)  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1098
       * (ii) we have a call to an overloaded function, with no errors!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1099
       */
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1100
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1101
      fdecl_return_type = base_type(f_decl->type_name);
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1102
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1103
      if (symbol->called_function_declaration == NULL) {
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1104
        /* Store the pointer to the declaration of the function being called.
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1105
         * This data will be used by stage 4 to call the correct function.
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1106
         * Mostly needed to disambiguate overloaded functions...
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1107
         * See comments in absyntax.def for more details
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1108
         */
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1109
        symbol->called_function_declaration = f_decl;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1110
        extensible_param_count = symbol->extensible_param_count;
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1111
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1112
        /* determine the base data type returned by the function being called... */
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1113
        return_data_type = fdecl_return_type;
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1114
      }
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1115
      else if (typeid(*return_data_type) != typeid(*fdecl_return_type)){
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1116
        return_data_type = common_literal(return_data_type, fdecl_return_type);
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1117
        overloaded_data_type = overloaded_return_type(return_data_type);
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1118
      }
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1119
      
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1120
      if (NULL == return_data_type) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1121
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1122
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1123
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1124
  if (overloaded_data_type != NULL) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1125
    for(current = lower; current != upper; current++) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1126
      function_declaration_c *f_decl = function_symtable.get_value(current);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1127
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1128
      /* check semantics of data passed in the function call... */
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1129
      check_nonformal_call(symbol, f_decl, true, error_count_ptr);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1130
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1131
      if (0 == error_count) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1132
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1133
        fdecl_return_type = base_type(f_decl->type_name);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1134
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1135
        if (typeid(*overloaded_data_type) == typeid(*fdecl_return_type)){
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1136
          /* Store the pointer to the declaration of the function being called.
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1137
           * This data will be used by stage 4 to call the correct function.
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1138
           * Mostly needed to disambiguate overloaded functions...
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1139
           * See comments in absyntax.def for more details
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1140
           */
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1141
          symbol->called_function_declaration = f_decl;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1142
          extensible_param_count = symbol->extensible_param_count;
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1143
        }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1144
      }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1145
    }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1146
  }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1147
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1148
  if (NULL == return_data_type) {
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1149
    /* No compatible function was found for this function call */
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1150
    STAGE3_ERROR(symbol, symbol, "Call to an overloaded function with invalid parameter type.");
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1151
  }
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1152
  else {
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1153
    symbol->extensible_param_count = extensible_param_count;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1154
    /* set the new data type of the default variable for the following verifications... */
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1155
    il_default_variable_type = return_data_type;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1156
  }
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1157
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1158
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1159
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1160
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1161
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1162
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1163
// SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1164
void *visit_expression_type_c::visit(il_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1165
  if (il_error)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1166
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1167
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1168
  symbol_c *il_default_variable_type_back = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1169
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1170
  il_parenthesis_level++;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1171
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1172
  if(symbol->il_operand != NULL) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1173
     il_default_variable_type = base_type((symbol_c *)symbol->il_operand->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1174
  } else {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1175
     il_default_variable_type = NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1176
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1177
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1178
  if(symbol->simple_instr_list != NULL) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1179
    symbol->simple_instr_list->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1180
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1181
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1182
  il_parenthesis_level--;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1183
  if (il_parenthesis_level < 0) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1184
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1185
  il_operand = symbol->simple_instr_list;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1186
  il_operand_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1187
  il_default_variable_type = il_default_variable_type_back;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1188
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1189
  /* Now check the if the data type semantics of operation are correct,
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1190
   * but only if no previous error has been found...
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1191
   */
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1192
  if (!il_error)
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1193
    symbol->il_expr_operator->accept(*this);
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1194
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1195
  il_operand_type = NULL;
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1196
  il_operand = NULL;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1197
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1198
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1199
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1200
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1201
#if 0
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1202
/*  il_jump_operator label */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1203
SYM_REF2(il_jump_operation_c, il_jump_operator, label)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1204
void *visit_expression_type_c::visit(il_jump_operation_c *symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1205
#endif
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1206
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1207
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1208
/*   il_call_operator prev_declared_fb_name
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1209
 * | il_call_operator prev_declared_fb_name '(' ')'
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1210
 * | il_call_operator prev_declared_fb_name '(' eol_list ')'
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1211
 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1212
 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1213
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1214
/* SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list) */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1215
void *visit_expression_type_c::visit(il_fb_call_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1216
  if (il_error)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1217
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1218
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1219
  /* first check whether the il_default_variable is of the correct type
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1220
   * for the CAL / CALC / CALCN operator being used...
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1221
   */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1222
  symbol->il_call_operator->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1223
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1224
  /* Now check the FB call itself... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1225
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1226
  /* First we find the declaration of the FB type of the FB instance being called... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1227
  /* e.g.  Function_block foo_fb_type
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1228
   *         ...
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1229
   *       End_Function_Block
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1230
   *
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1231
   *       Program test
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1232
   *         var fb1 : foo_fb_type; end_var
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1233
   *         fb1(...)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1234
   *       End_Program
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1235
   *
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1236
   *    search_varfb_instance_type->get_basetype_decl( identifier_c("fb1") )
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1237
   *    in the scope of Program 'test'
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1238
   *    will return the fb declaration of foo_fb_type !!
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1239
   */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1240
#if 0
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1241
  symbol_c *fb_decl_symbol = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1242
    /* The following should never occur. The function block must be defined, 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1243
     * and the FB type being called MUST be in the symtable... 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1244
     * This was all already checked at stage 2!
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1245
     */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1246
  if (NULL == fb_decl_symbol) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1247
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1248
  function_block_declaration_c *fb_decl = dynamic_cast<function_block_declaration_c *>(fb_decl_symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1249
    /* should never occur. ... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1250
  if (NULL == fb_decl) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1251
#endif
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1252
  symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1253
    /* The following should never occur. The function block must be defined, 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1254
     * and the FB type being called MUST be in the symtable... 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1255
     * This was all already checked at stage 2!
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1256
     */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1257
  if (NULL == fb_decl) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1258
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1259
  /* now check the semantics of the fb call... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1260
  /* If the syntax parser is working correctly, exactly one of the 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1261
   * following two symbols will be NULL, while the other is != NULL.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1262
   */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1263
  if (NULL != symbol->il_operand_list)  check_nonformal_call(symbol, fb_decl);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1264
  if (NULL != symbol->il_param_list)    check_formal_call   (symbol, fb_decl);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1265
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1266
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1267
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1268
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1269
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1270
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1271
/* | function_name '(' eol_list [il_param_list] ')' */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1272
/* SYM_REF2(il_formal_funct_call_c, function_name, il_param_list) */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1273
void *visit_expression_type_c::visit(il_formal_funct_call_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1274
  if (il_error)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1275
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1276
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1277
  symbol_c *return_data_type = NULL;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1278
  symbol_c* fdecl_return_type;
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1279
  symbol_c *overloaded_data_type = NULL;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1280
  int extensible_param_count = -1;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1281
  symbol->called_function_declaration = NULL;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1282
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1283
  function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1284
  function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name);
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1285
  function_symtable_t::iterator current;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1286
  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1287
  if (lower == function_symtable.end()) {
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1288
    function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1289
    if (current_function_type == function_none) ERROR;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1290
    return NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1291
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1292
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1293
  int error_count = 0; 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1294
  int *error_count_ptr = NULL;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1295
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1296
  function_symtable_t::iterator second = lower;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1297
  second++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1298
  if (second != upper) 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1299
    /* This is a call to an overloaded function... */  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1300
    error_count_ptr = &error_count;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1301
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1302
  for(current = lower; current != upper; current++) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1303
    function_declaration_c *f_decl = function_symtable.get_value(current);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1304
  
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1305
    /* check semantics of data passed in the function call... */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1306
    check_formal_call(symbol, f_decl, error_count_ptr);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1307
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1308
    if (0 == error_count) {
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1309
      /* Either: 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1310
       * (i) we have a call to a non-overloaded function (error_cnt_ptr is NULL!, so error_count won't change!)  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1311
       * (ii) we have a call to an overloaded function, with no errors!
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1312
       */
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1313
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1314
      fdecl_return_type = base_type(f_decl->type_name);
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1315
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1316
      if (symbol->called_function_declaration == NULL) {
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1317
        /* Store the pointer to the declaration of the function being called.
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1318
         * This data will be used by stage 4 to call the correct function.
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1319
         * Mostly needed to disambiguate overloaded functions...
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1320
         * See comments in absyntax.def for more details
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1321
         */
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1322
        symbol->called_function_declaration = f_decl;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1323
        extensible_param_count = symbol->extensible_param_count;
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1324
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1325
        /* determine the base data type returned by the function being called... */
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1326
        return_data_type = fdecl_return_type;
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1327
      }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1328
      else if (typeid(*return_data_type) != typeid(*fdecl_return_type)){
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1329
        return_data_type = common_literal(return_data_type, fdecl_return_type);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1330
        overloaded_data_type = overloaded_return_type(return_data_type);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1331
      }
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1332
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1333
      /* the following should never occur. If it does, then we have a bug in the syntax parser (stage 2)... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1334
      if (NULL == return_data_type) ERROR;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1335
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1336
    }
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1337
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  1338
  
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1339
  if (overloaded_data_type != NULL) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1340
    for(current = lower; current != upper; current++) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1341
      function_declaration_c *f_decl = function_symtable.get_value(current);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1342
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1343
      /* check semantics of data passed in the function call... */
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1344
      check_formal_call(symbol, f_decl, error_count_ptr);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1345
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1346
      if (0 == error_count) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1347
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1348
        fdecl_return_type = base_type(f_decl->type_name);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1349
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1350
        if (typeid(*overloaded_data_type) == typeid(*fdecl_return_type)){
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1351
          /* Store the pointer to the declaration of the function being called.
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1352
           * This data will be used by stage 4 to call the correct function.
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1353
           * Mostly needed to disambiguate overloaded functions...
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1354
           * See comments in absyntax.def for more details
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1355
           */
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1356
          symbol->called_function_declaration = f_decl;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1357
          extensible_param_count = symbol->extensible_param_count;
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1358
        }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1359
      }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1360
    }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1361
  }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1362
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1363
  if (NULL == return_data_type) {
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1364
    /* No compatible function was found for this function call */
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  1365
    STAGE3_ERROR(symbol, symbol, "Call to an overloaded function with invalid parameter type.");
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1366
  }
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1367
  else {
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  1368
    symbol->extensible_param_count = extensible_param_count;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1369
    /* the data type of the data returned by the function, and stored in the il default variable... */
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1370
    il_default_variable_type = return_data_type;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1371
  }
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  1372
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1373
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1374
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1375
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1376
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1377
#if 0
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1378
/* | il_operand_list ',' il_operand */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1379
SYM_LIST(il_operand_list_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1380
void *visit_expression_type_c::visit(il_operand_list_c *symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1381
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1382
/* | simple_instr_list il_simple_instruction */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1383
SYM_LIST(simple_instr_list_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1384
void *visit_expression_type_c::visit(simple_instr_list_c *symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1385
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1386
/* | il_initial_param_list il_param_instruction */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1387
SYM_LIST(il_param_list_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1388
void *visit_expression_type_c::visit(il_param_list_c *symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1389
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1390
/*  il_assign_operator il_operand
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1391
 * | il_assign_operator '(' eol_list simple_instr_list ')'
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1392
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1393
SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1394
void *visit_expression_type_c::visit(il_param_assignment_c *symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1395
/*  il_assign_out_operator variable */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1396
SYM_REF2(il_param_out_assignment_c, il_assign_out_operator, variable)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1397
void *visit_expression_type_c::visit(il_param_out_assignment_c *symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1398
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1399
#endif
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1400
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1401
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1402
/*******************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1403
/* B 2.2 Operators */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1404
/*******************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1405
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1406
//SYM_REF0(LD_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1407
void *visit_expression_type_c::visit(LD_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1408
  if (0 == il_parenthesis_level)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1409
    il_error = false;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1410
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1411
  if(il_operand_type == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1412
      STAGE3_ERROR(symbol, symbol, "LD operator requires an operand.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1413
  il_default_variable_type = il_operand_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1414
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1415
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1416
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1417
// SYM_REF0(LDN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1418
void *visit_expression_type_c::visit(LDN_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1419
  if(il_operand_type == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1420
      STAGE3_ERROR(symbol, symbol, "LDN operator requires an operand.");
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1421
  if(!is_ANY_BIT_compatible(il_operand_type))
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1422
      STAGE3_ERROR(symbol, il_operand, "invalid data type of LDN operand, should be of type ANY_BIT.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1423
  il_default_variable_type = il_operand_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1424
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1425
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1426
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1427
// SYM_REF0(ST_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1428
void *visit_expression_type_c::visit(ST_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1429
  verify_null(symbol);
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1430
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1431
  if(!is_valid_assignment(il_operand_type, il_default_variable_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1432
    STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1433
  /* TODO: check whether il_operand_type is an LVALUE !! */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1434
  /* data type of il_default_variable_type is unchanged... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1435
  // il_default_variable_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1436
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1437
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1438
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1439
// SYM_REF0(STN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1440
 void *visit_expression_type_c::visit(STN_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1441
  verify_null(symbol);
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1442
  if(!is_valid_assignment(il_operand_type, il_default_variable_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1443
    STAGE3_ERROR(symbol, symbol, "Type mismatch in ST operation.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1444
  /* TODO: check whether il_operand_type is an LVALUE !! */
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1445
  if(!is_ANY_BIT_compatible(il_default_variable_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1446
      STAGE3_ERROR(symbol, symbol, "invalid data type of il_default_variable for STN operand, should be of type ANY_BIT.");
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1447
  if(!is_ANY_BIT_compatible(il_operand_type))
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1448
      STAGE3_ERROR(symbol, il_operand, "invalid data type of STN operand, should be of type ANY_BIT.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1449
  /* data type of il_default_variable_type is unchanged... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1450
  // il_default_variable_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1451
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1452
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1453
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1454
//SYM_REF0(NOT_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1455
void *visit_expression_type_c::visit(NOT_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1456
  if(il_operand_type != NULL){
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1457
    STAGE3_ERROR(symbol, il_operand, "NOT operator may not have an operand.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1458
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1459
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1460
  if(il_default_variable_type == NULL) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1461
    STAGE3_ERROR(symbol, symbol, "Il default variable should not be NULL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1462
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1463
  }
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1464
  if(!is_ANY_BIT_compatible(il_default_variable_type)) {
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1465
    STAGE3_ERROR(symbol, symbol, "Il default variable should be of type ANY_BIT.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1466
    return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1467
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1468
  /* data type of il_default_variable_type is unchanged... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1469
  // il_default_variable_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1470
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1471
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1472
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1473
// SYM_REF0(S_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1474
void *visit_expression_type_c::visit(S_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1475
  verify_null(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1476
  if (!is_BOOL_type(il_default_variable_type)) {STAGE3_ERROR(symbol, symbol, "IL default variable should be BOOL type.");}
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1477
  if (!is_BOOL_type(il_operand_type)) {STAGE3_ERROR(symbol, il_operand, "operator S requires operand of type BOOL.");}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1478
  /* TODO: check whether il_operand_type is an LVALUE !! */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1479
  /* data type of il_default_variable_type is unchanged... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1480
  // il_default_variable_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1481
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1482
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1483
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1484
// SYM_REF0(R_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1485
void *visit_expression_type_c::visit(R_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1486
  verify_null(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1487
  if (!is_BOOL_type(il_default_variable_type)) {STAGE3_ERROR(symbol, symbol, "IL default variable should be BOOL type.");}
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1488
  if (!is_BOOL_type(il_operand_type)) {STAGE3_ERROR(symbol, il_operand, "operator R requires operand of type BOOL.");}
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1489
  /* TODO: check whether il_operand_type is an LVALUE !! */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1490
  /* data type of il_default_variable_type is unchanged... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1491
  // il_default_variable_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1492
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1493
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1494
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1495
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1496
// SYM_REF0(S1_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1497
void *visit_expression_type_c::visit(S1_operator_c *symbol){
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1498
  check_il_fbcall(symbol, "S1");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1499
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1500
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1501
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1502
// SYM_REF0(R1_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1503
void *visit_expression_type_c::visit(R1_operator_c *symbol) {
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1504
  check_il_fbcall(symbol, "R1");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1505
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1506
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1507
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1508
// SYM_REF0(CLK_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1509
void *visit_expression_type_c::visit(CLK_operator_c *symbol) {
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1510
  check_il_fbcall(symbol, "CLK");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1511
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1512
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1513
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1514
// SYM_REF0(CU_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1515
void *visit_expression_type_c::visit(CU_operator_c *symbol) {
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1516
  check_il_fbcall(symbol, "CU");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1517
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1518
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1519
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1520
// SYM_REF0(CD_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1521
void *visit_expression_type_c::visit(CD_operator_c *symbol) {
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1522
  check_il_fbcall(symbol, "CD");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1523
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1524
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1525
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1526
// SYM_REF0(PV_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1527
void *visit_expression_type_c::visit(PV_operator_c *symbol) {
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1528
  check_il_fbcall(symbol, "PV");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1529
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1530
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1531
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1532
// SYM_REF0(IN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1533
void *visit_expression_type_c::visit(IN_operator_c *symbol) {
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1534
  check_il_fbcall(symbol, "IN");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1535
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1536
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1537
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1538
// SYM_REF0(PT_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1539
void *visit_expression_type_c::visit(PT_operator_c *symbol) {
323
d3f2ef59b310 Clean up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  1540
  check_il_fbcall(symbol, "PT");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1541
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1542
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1543
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1544
//SYM_REF0(AND_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1545
void *visit_expression_type_c::visit(AND_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1546
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1547
  il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1548
                                                symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1549
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1550
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1551
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1552
//SYM_REF0(OR_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1553
void *visit_expression_type_c::visit(OR_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1554
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1555
  il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1556
                                                symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1557
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1558
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1559
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1560
//SYM_REF0(XOR_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1561
void *visit_expression_type_c::visit(XOR_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1562
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1563
  il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1564
                                                symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1565
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1566
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1567
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1568
// SYM_REF0(ANDN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1569
void *visit_expression_type_c::visit(ANDN_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1570
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1571
  il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1572
                                                symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1573
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1574
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1575
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1576
// SYM_REF0(ORN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1577
void *visit_expression_type_c::visit(ORN_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1578
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1579
  il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1580
                                                symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1581
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1582
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1583
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1584
// SYM_REF0(XORN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1585
void *visit_expression_type_c::visit(XORN_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1586
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1587
  il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_BIT_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1588
                                                symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1589
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1590
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1591
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1592
// SYM_REF0(ADD_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1593
void *visit_expression_type_c::visit(ADD_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1594
  verify_null(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1595
  symbol_c *left_type  = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1596
  symbol_c *right_type = il_operand_type;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1597
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1598
/* The following is not required, it is already handled by compute_expression() ... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1599
/*
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1600
  if      (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1601
    il_default_variable_type = &time_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1602
*/
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1603
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1604
  if      (is_type(left_type, tod_type_name_c)      && is_type(right_type, time_type_name_c))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1605
    il_default_variable_type = &tod_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1606
  else if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1607
    il_default_variable_type = &tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1608
  else if (is_type(left_type, tod_type_name_c)      && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1609
    il_default_variable_type = &tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1610
  else if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1611
    il_default_variable_type = &safetod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1612
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1613
  else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, time_type_name_c))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1614
    il_default_variable_type = &dt_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1615
  else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1616
    il_default_variable_type = &dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1617
  else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1618
    il_default_variable_type = &dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1619
  else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1620
    il_default_variable_type = &safedt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1621
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1622
  else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1623
                                                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1624
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1625
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1626
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1627
// SYM_REF0(SUB_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1628
void *visit_expression_type_c::visit(SUB_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1629
  verify_null(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1630
  symbol_c *left_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1631
  symbol_c *right_type = il_operand_type;;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1632
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1633
/* The following is not required, it is already handled by compute_expression() ... */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1634
/*
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1635
  if      (typeid(*left_type) == typeid(time_type_name_c) && typeid(*right_type) == typeid(time_type_name_c))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1636
    il_default_variable_type = &time_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1637
*/
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1638
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1639
  if      (is_type(left_type, tod_type_name_c)       && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1640
    il_default_variable_type = &tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1641
  else if (is_type(left_type, safetod_type_name_c)   && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1642
    il_default_variable_type = &tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1643
  else if (is_type(left_type, tod_type_name_c)       && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1644
    il_default_variable_type = &tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1645
  else if (is_type(left_type, safetod_type_name_c)   && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1646
    il_default_variable_type = &safetod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1647
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1648
  else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1649
    il_default_variable_type = &dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1650
  else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1651
    il_default_variable_type = &dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1652
  else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1653
    il_default_variable_type = &dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1654
  else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1655
    il_default_variable_type = &safedt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1656
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1657
  else if (is_type(left_type, date_type_name_c)     && is_type(right_type, date_type_name_c))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1658
    il_default_variable_type = &time_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1659
  else if (is_type(left_type, safedate_type_name_c) && is_type(right_type, date_type_name_c))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1660
    il_default_variable_type = &time_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1661
  else if (is_type(left_type, date_type_name_c)     && is_type(right_type, safedate_type_name_c))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1662
    il_default_variable_type = &time_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1663
  else if (is_type(left_type, safedate_type_name_c) && is_type(right_type, safedate_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1664
    il_default_variable_type = &safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1665
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1666
  else if (is_type(left_type, tod_type_name_c)      && is_type(right_type, tod_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1667
    il_default_variable_type = &time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1668
  else if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, tod_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1669
    il_default_variable_type = &time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1670
  else if (is_type(left_type, tod_type_name_c)      && is_type(right_type, safetod_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1671
    il_default_variable_type = &time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1672
  else if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, safetod_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1673
    il_default_variable_type = &safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1674
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1675
  else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, dt_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1676
    il_default_variable_type = &time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1677
  else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, dt_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1678
    il_default_variable_type = &time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1679
  else if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safedt_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1680
    il_default_variable_type = &time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1681
  else if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safedt_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1682
    il_default_variable_type = &safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1683
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1684
  else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1685
                                                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1686
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1687
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1688
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1689
// SYM_REF0(MUL_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1690
void *visit_expression_type_c::visit(MUL_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1691
  verify_null(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1692
  symbol_c *left_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1693
  symbol_c *right_type = il_operand_type;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1694
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1695
  if      (is_type(left_type, time_type_name_c)     && is_ANY_NUM_compatible(right_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1696
    il_default_variable_type = &time_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1697
  else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1698
    il_default_variable_type = &time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1699
  else if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1700
    il_default_variable_type = &safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1701
  /* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1702
   * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1703
   */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1704
  else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1705
    il_default_variable_type = &safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1706
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1707
  else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1708
                                                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1709
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1710
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1711
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1712
// SYM_REF0(DIV_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1713
void *visit_expression_type_c::visit(DIV_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1714
  verify_null(symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1715
  symbol_c *left_type = il_default_variable_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1716
  symbol_c *right_type = il_operand_type;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1717
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1718
  if      (is_type(left_type, time_type_name_c)     && is_ANY_NUM_compatible(right_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1719
    il_default_variable_type = &time_type_name;
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1720
  else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1721
    il_default_variable_type = &time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1722
  else if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1723
    il_default_variable_type = &safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1724
  /* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1725
   * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1726
   */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1727
  else if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1728
    il_default_variable_type = &safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1729
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1730
  else il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_NUM_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1731
                                                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1732
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1733
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1734
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1735
// SYM_REF0(MOD_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1736
void *visit_expression_type_c::visit(MOD_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1737
  verify_null(symbol);
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1738
  il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_INT_compatible,
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1739
                                                symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1740
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1741
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1742
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1743
// SYM_REF0(GT_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1744
void *visit_expression_type_c::visit(GT_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1745
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1746
  compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1747
                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1748
  il_default_variable_type = &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1749
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1750
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1751
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1752
//SYM_REF0(GE_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1753
void *visit_expression_type_c::visit(GE_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1754
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1755
  compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1756
                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1757
  il_default_variable_type = &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1758
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1759
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1760
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1761
//SYM_REF0(EQ_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1762
void *visit_expression_type_c::visit(EQ_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1763
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1764
  compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1765
                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1766
  il_default_variable_type = &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1767
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1768
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1769
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1770
//SYM_REF0(LT_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1771
void *visit_expression_type_c::visit(LT_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1772
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1773
  compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1774
                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1775
  il_default_variable_type = &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1776
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1777
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1778
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1779
//SYM_REF0(LE_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1780
void *visit_expression_type_c::visit(LE_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1781
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1782
  compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1783
                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1784
  il_default_variable_type = &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1785
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1786
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1787
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1788
//SYM_REF0(NE_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1789
void *visit_expression_type_c::visit(NE_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1790
  verify_null(symbol);
266
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1791
  compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible,
2f6d8866ec8d Fixing error messages for IL semantic errors (brocken in a previous changeset/commit).
Mario de Sousa <msousa@fe.up.pt>
parents: 263
diff changeset
  1792
                     symbol                  , il_operand);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1793
  il_default_variable_type = &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1794
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1795
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1796
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1797
// SYM_REF0(CAL_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1798
void *visit_expression_type_c::visit(CAL_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1799
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1800
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1801
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1802
// SYM_REF0(CALC_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1803
void *visit_expression_type_c::visit(CALC_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1804
  if(il_default_variable_type == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1805
    STAGE3_ERROR(symbol, symbol, "CALC: il default variable should not be NULL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1806
  if (!is_BOOL_type(il_default_variable_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1807
    STAGE3_ERROR(symbol, symbol, "CALC operator requires il_default_variable to be of type BOOL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1808
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1809
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1810
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1811
// SYM_REF0(CALCN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1812
void *visit_expression_type_c::visit(CALCN_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1813
  if(il_default_variable_type == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1814
    STAGE3_ERROR(symbol, symbol, "CALCN: il_default_variable should not be NULL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1815
  if (!is_BOOL_type(il_default_variable_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1816
    STAGE3_ERROR(symbol, symbol, "CALCN operator requires il_default_variable to be of type BOOL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1817
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1818
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1819
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1820
// SYM_REF0(RET_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1821
void *visit_expression_type_c::visit(RET_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1822
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1823
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1824
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1825
// SYM_REF0(RETC_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1826
void *visit_expression_type_c::visit(RETC_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1827
  if(il_default_variable_type == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1828
    STAGE3_ERROR(symbol, symbol, "RETC: il default variable should not be NULL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1829
  if (!is_BOOL_type(il_default_variable_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1830
    STAGE3_ERROR(symbol, symbol, "RETC operator requires il_default_variable to be of type BOOL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1831
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1832
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1833
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1834
// SYM_REF0(RETCN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1835
void *visit_expression_type_c::visit(RETCN_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1836
  if(il_default_variable_type == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1837
    STAGE3_ERROR(symbol, symbol, "RETCN: il_default_variable should not be NULL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1838
  if (!is_BOOL_type(il_default_variable_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1839
    STAGE3_ERROR(symbol, symbol, "RETCN operator requires il_default_variable to be of type BOOL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1840
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1841
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1842
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1843
// SYM_REF0(JMP_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1844
void *visit_expression_type_c::visit(JMP_operator_c *symbol){
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1845
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1846
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1847
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1848
// SYM_REF0(JMPC_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1849
void *visit_expression_type_c::visit(JMPC_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1850
  if(il_default_variable_type == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1851
    STAGE3_ERROR(symbol, symbol, "JMPC: il default variable should not be NULL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1852
  if (!is_BOOL_type(il_default_variable_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1853
    STAGE3_ERROR(symbol, symbol, "JMPC operator requires il_default_variable to be of type BOOL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1854
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1855
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1856
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1857
// SYM_REF0(JMPCN_operator_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1858
void *visit_expression_type_c::visit(JMPCN_operator_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1859
  if(il_default_variable_type == NULL)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1860
    STAGE3_ERROR(symbol, symbol, "JMPCN: il_default_variable should not be NULL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1861
  if (!is_BOOL_type(il_default_variable_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1862
    STAGE3_ERROR(symbol, symbol, "JMPCN operator requires il_default_variable to be of type BOOL.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1863
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1864
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1865
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1866
/* Symbol class handled together with function call checks */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1867
/*  any_identifier ASSIGN */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1868
// SYM_REF1(il_assign_operator_c, variable_name)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1869
// void *visit_expression_type_c::visit(il_assign_operator_c *symbol, variable_name);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1870
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1871
/* Symbol class handled together with function call checks */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1872
/*| [NOT] any_identifier SENDTO */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1873
// SYM_REF2(il_assign_out_operator_c, option, variable_name)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1874
// void *visit_expression_type_c::visit(il_assign_operator_c *symbol, option, variable_name);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1875
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1876
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1877
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1878
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1879
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1880
/***************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1881
/* B.3 - Language ST (Structured Text) */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1882
/***************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1883
/***********************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1884
/* B 3.1 - Expressions */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1885
/***********************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1886
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1887
void *visit_expression_type_c::visit(or_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1888
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1889
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1890
  return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1891
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1892
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1893
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1894
void *visit_expression_type_c::visit(xor_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1895
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1896
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1897
  return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1898
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1899
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1900
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1901
void *visit_expression_type_c::visit(and_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1902
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1903
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1904
  return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1905
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1906
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1907
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1908
void *visit_expression_type_c::visit(equ_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1909
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1910
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
390
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
  1911
  compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_OR_ENUMERATED_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1912
  return &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1913
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1914
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1915
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1916
void *visit_expression_type_c::visit(notequ_expression_c *symbol)  {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1917
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1918
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
390
9cf96d45853d Fix bug when using enumerated type in equ_expression or notequ_expression
laurent
parents: 386
diff changeset
  1919
  compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_OR_ENUMERATED_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1920
  return &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1921
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1922
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1923
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1924
void *visit_expression_type_c::visit(lt_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1925
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1926
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1927
  compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1928
  return &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1929
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1930
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1931
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1932
void *visit_expression_type_c::visit(gt_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1933
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1934
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1935
  compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1936
  return &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1937
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1938
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1939
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1940
void *visit_expression_type_c::visit(le_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1941
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1942
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1943
  compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1944
  return &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1945
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1946
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1947
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1948
void *visit_expression_type_c::visit(ge_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1949
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1950
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1951
  compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1952
  return &search_expression_type_c::bool_type_name;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1953
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1954
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1955
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1956
void *visit_expression_type_c::visit(add_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1957
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1958
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1959
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1960
/* The following is already checked in compute_expression */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1961
/*
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1962
  if (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1963
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1964
*/
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1965
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1966
  if (is_type(left_type, tod_type_name_c)      && is_type(right_type, time_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1967
    return (void *)&tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1968
  if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, time_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1969
    return (void *)&tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1970
  if (is_type(left_type, tod_type_name_c)      && is_type(right_type, safetime_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1971
    return (void *)&tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1972
  if (is_type(left_type, safetod_type_name_c)  && is_type(right_type, safetime_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1973
    return (void *)&safetod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1974
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1975
  if (is_type(left_type, dt_type_name_c)       && is_type(right_type, time_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1976
    return (void *)&dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1977
  if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, time_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1978
    return (void *)&dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1979
  if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safetime_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1980
    return (void *)&dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1981
  if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safetime_type_name_c)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1982
    return (void *)&safedt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1983
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  1984
  return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1985
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1986
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1987
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1988
void *visit_expression_type_c::visit(sub_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1989
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  1990
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1991
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1992
/* The following is already checked in compute_expression */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1993
/*
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1994
  if (is_type(left_type, time_type_name_c) && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1995
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1996
*/
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1997
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1998
  if (is_type(left_type, tod_type_name_c)     && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  1999
    return (void *)&tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2000
  if (is_type(left_type, safetod_type_name_c) && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2001
    return (void *)&tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2002
  if (is_type(left_type, tod_type_name_c)     && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2003
    return (void *)&tod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2004
  if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2005
    return (void *)&safetod_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2006
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2007
  if (is_type(left_type, dt_type_name_c)     && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2008
    return (void *)&dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2009
  if (is_type(left_type, safedt_type_name_c) && is_type(right_type, time_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2010
    return (void *)&dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2011
  if (is_type(left_type, dt_type_name_c)     && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2012
    return (void *)&dt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2013
  if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safetime_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2014
    return (void *)&safedt_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2015
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2016
  if (is_type(left_type, tod_type_name_c)     && is_type(right_type, tod_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2017
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2018
  if (is_type(left_type, safetod_type_name_c) && is_type(right_type, tod_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2019
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2020
  if (is_type(left_type, tod_type_name_c)     && is_type(right_type, safetod_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2021
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2022
  if (is_type(left_type, safetod_type_name_c) && is_type(right_type, safetod_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2023
    return (void *)&safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2024
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2025
  if (is_type(left_type, date_type_name_c)     && is_type(right_type, date_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2026
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2027
  if (is_type(left_type, safedate_type_name_c) && is_type(right_type, date_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2028
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2029
  if (is_type(left_type, date_type_name_c)     && is_type(right_type, safedate_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2030
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2031
  if (is_type(left_type, safedate_type_name_c) && is_type(right_type, safedate_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2032
    return (void *)&safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2033
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2034
  if (is_type(left_type, dt_type_name_c)     && is_type(right_type, dt_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2035
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2036
  if (is_type(left_type, safedt_type_name_c) && is_type(right_type, dt_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2037
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2038
  if (is_type(left_type, dt_type_name_c)     && is_type(right_type, safedt_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2039
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2040
  if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safedt_type_name_c))
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2041
    return (void *)&safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2042
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  2043
  return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2044
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2045
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2046
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2047
void *visit_expression_type_c::visit(mul_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2048
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2049
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2050
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2051
  if (is_type(left_type, time_type_name_c)     && is_ANY_NUM_compatible(right_type)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2052
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2053
  if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2054
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2055
  if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2056
    return (void *)&safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2057
  /* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2058
   * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2059
   */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2060
  if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2061
    return (void *)&safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2062
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  2063
  return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2064
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2065
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2066
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2067
void *visit_expression_type_c::visit(div_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2068
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2069
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2070
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2071
  if (is_type(left_type, time_type_name_c)     && is_ANY_NUM_compatible(right_type)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2072
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2073
  if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_type(right_type)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2074
    return (void *)&time_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2075
  if (is_type(left_type, safetime_type_name_c) && is_ANY_SAFENUM_type(right_type)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2076
    return (void *)&safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2077
  /* Since we have already checked for ANY_NUM_type and ANY_SAFENUM_type in the previous lines,
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2078
   * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2079
   */
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2080
  if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type)) 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2081
    return (void *)&safetime_type_name;
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2082
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  2083
  return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2084
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2085
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2086
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2087
void *visit_expression_type_c::visit(mod_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2088
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2089
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  2090
  return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_INT_compatible, symbol->l_exp, symbol->r_exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2091
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2092
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2093
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2094
void *visit_expression_type_c::visit(power_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2095
  symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2096
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2097
  if (!is_ANY_REAL_compatible(left_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2098
    STAGE3_ERROR(symbol->l_exp, symbol->l_exp, "first operand of ** operator has invalid data type, should be of type ANY_REAL.");
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2099
  if (!is_ANY_NUM_compatible(right_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2100
    STAGE3_ERROR(symbol->r_exp, symbol->r_exp, "second operand of ** operator has invalid data type, should be of type ANY_NUM.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2101
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2102
  return (void *)left_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2103
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2104
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2105
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2106
void *visit_expression_type_c::visit(neg_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2107
  symbol_c *exp_type = base_type((symbol_c *)symbol->exp->accept(*this));
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2108
  if (!is_ANY_MAGNITUDE_compatible(exp_type))
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2109
    STAGE3_ERROR(symbol, symbol, "operand of negate expression '-' has invalid data type, should be of type ANY_MAGNITUDE.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2110
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2111
  return exp_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2112
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2113
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2114
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2115
void *visit_expression_type_c::visit(not_expression_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2116
  symbol_c *type = base_type((symbol_c *)symbol->exp->accept(*this));
360
f4ce1b1c2112 Print error messages when data type errors in ST expressions are detected.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
  2117
  return compute_expression(type, type, &visit_expression_type_c::is_ANY_BIT_compatible, NULL, symbol->exp);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2118
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2119
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2120
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2121
void *visit_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: 333
diff changeset
  2122
  function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2123
  function_symtable_t::iterator upper = function_symtable.upper_bound(symbol->function_name);
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2124
  function_symtable_t::iterator current;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2125
  if (lower == function_symtable.end()) ERROR;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2126
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2127
  symbol_c* return_data_type;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2128
  symbol_c* fdecl_return_type;
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2129
  symbol_c* overloaded_data_type = NULL;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  2130
  int extensible_param_count = -1;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2131
  symbol->called_function_declaration = NULL;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2132
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2133
  function_symtable_t::iterator second = lower;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2134
  second++;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2135
  if (second == upper) {
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2136
    /* call to a function that is not overloaded. */
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2137
    /* now check the semantics of the function call... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2138
    /* If the syntax parser is working correctly, exactly one of the 
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2139
     * following two symbols will be NULL, while the other is != NULL.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2140
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2141
    function_declaration_c *f_decl = function_symtable.get_value(lower);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2142
    if (symbol->   formal_param_list != NULL) check_formal_call   (symbol, f_decl);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2143
    if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, f_decl);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2144
    /* Store the pointer to the declaration of the function being called.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2145
     * This data will be used by stage 4 to call the correct function.
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2146
     * Mostly needed to disambiguate overloaded functions...
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2147
     * See comments in absyntax.def for more details
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2148
     */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2149
    symbol->called_function_declaration = f_decl;
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2150
    return base_type(f_decl->type_name);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2151
  }  
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2152
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2153
  /* This is a call to an overloaded function... */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2154
  if (debug) printf("visit_expression_type_c::visit(function_invocation_c *symbol): FOUND CALL TO OVERLOADED FUNCTION!!\n");
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2155
  for(current = lower; current != upper; current++) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2156
    if (debug) printf("visit_expression_type_c::visit(function_invocation_c *symbol): FOUND CALL TO OVERLOADED FUNCTION!! iterating...\n");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2157
    int error_count = 0; 
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2158
    function_declaration_c *f_decl = function_symtable.get_value(current);
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2159
    if (symbol->   formal_param_list != NULL) check_formal_call   (symbol, f_decl, &error_count);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2160
    if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, f_decl, false, &error_count);
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2161
    if (0 == error_count) {
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2162
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2163
      fdecl_return_type = base_type(f_decl->type_name);
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2164
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2165
      if (symbol->called_function_declaration == NULL) {
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2166
        /* Store the pointer to the declaration of the function being called.
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2167
         * This data will be used by stage 4 to call the correct function.
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2168
         * Mostly needed to disambiguate overloaded functions...
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2169
         * See comments in absyntax.def for more details
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2170
         */
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2171
        symbol->called_function_declaration = f_decl;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  2172
        extensible_param_count = symbol->extensible_param_count;
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2173
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2174
        /* determine the base data type returned by the function being called... */
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2175
        return_data_type = fdecl_return_type;
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2176
      }
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2177
      else if (typeid(*return_data_type) != typeid(*fdecl_return_type)){
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2178
          return_data_type = common_literal(return_data_type, fdecl_return_type);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2179
          overloaded_data_type = overloaded_return_type(return_data_type);
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2180
      }
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2181
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2182
      if (NULL == return_data_type) ERROR;
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2183
    }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2184
  }
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2185
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2186
  if (overloaded_data_type != NULL) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2187
    for(current = lower; current != upper; current++) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2188
      function_declaration_c *f_decl = function_symtable.get_value(current);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2189
      int error_count = 0;
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2190
      if (symbol->   formal_param_list != NULL) check_formal_call   (symbol, f_decl, &error_count);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2191
      if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, f_decl, false, &error_count);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2192
      if (0 == error_count) {
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2193
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2194
        fdecl_return_type = base_type(f_decl->type_name);
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2195
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2196
        if (typeid(*overloaded_data_type) == typeid(*fdecl_return_type)){
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2197
          /* Store the pointer to the declaration of the function being called.
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2198
           * This data will be used by stage 4 to call the correct function.
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2199
           * Mostly needed to disambiguate overloaded functions...
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2200
           * See comments in absyntax.def for more details
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2201
           */
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2202
          symbol->called_function_declaration = f_decl;
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  2203
          extensible_param_count = symbol->extensible_param_count;
406
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2204
        }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2205
      }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2206
    }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2207
  }
6381589697ff Fix bug with overloaded function due to literal input values
laurent
parents: 399
diff changeset
  2208
407
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  2209
  if (return_data_type != NULL) {
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  2210
	symbol->extensible_param_count = extensible_param_count;
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  2211
	return return_data_type;
2d77f0f77773 Fix bug in code generated for MUL function
laurent
parents: 406
diff changeset
  2212
  }
399
55b074ea7255 Fix bug with functions like LEN and TRUNC that have overloaded return type for same inputs type
laurent
parents: 390
diff changeset
  2213
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2214
  /* No compatible function was found for this function call */
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2215
  STAGE3_ERROR(symbol, symbol, "Call to an overloaded function with invalid parameter type.");
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 333
diff changeset
  2216
  return NULL;
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2217
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2218
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2219
/********************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2220
/* B 3.2 Statements */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2221
/********************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2222
// SYM_LIST(statement_list_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2223
/* The visitor of the base class search_visitor_c will handle calling each instruction in the list.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2224
 * We do not need to do anything here...
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2225
 */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2226
// void *visit_expression_type_c::visit(statement_list_c *symbol)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2227
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2228
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2229
/*********************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2230
/* B 3.2.1 Assignment Statements */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2231
/*********************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2232
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2233
void *visit_expression_type_c::visit(assignment_statement_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2234
  symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2235
  symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2236
305
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2237
  if (debug) {
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2238
    printf("visit_expression_type_c::visit(assignment_statement_c) called. Checking --->");  
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2239
    symbolic_variable_c *hi = dynamic_cast<symbolic_variable_c *>(symbol->l_exp);  
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2240
    if (hi != NULL) {
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2241
      identifier_c *hi1 = dynamic_cast<identifier_c *>(hi->var_name);  
331
e08e14782a4f Fix warnings when compiling matiec
laurent
parents: 324
diff changeset
  2242
      if (hi1 != NULL) printf("%s", hi1->value);
305
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2243
    }
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2244
    printf(" := ");
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2245
    hex_integer_c *hi2 = dynamic_cast<hex_integer_c *>(symbol->r_exp);  
331
e08e14782a4f Fix warnings when compiling matiec
laurent
parents: 324
diff changeset
  2246
    if (hi2 != NULL) printf("%s", hi2->value);
305
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2247
    printf("\n");
fe5cb87610fa When checking semantics of expressions, skip semantic checking of data type definitions
Mario de Sousa <msousa@fe.up.pt>
parents: 289
diff changeset
  2248
  } // if (debug)
367
6d94128ba5ad Add checks for undefined structure elements used IEC 61131-3 source code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 365
diff changeset
  2249
6d94128ba5ad Add checks for undefined structure elements used IEC 61131-3 source code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 365
diff changeset
  2250
  if        (NULL == left_type) {
386
606443ffd589 Fix semantic verification of enumerated data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 367
diff changeset
  2251
    STAGE3_ERROR(symbol->l_exp, symbol->l_exp, "Could not determine data type of expression (undefined variable, constant, or structure element?).\n");
367
6d94128ba5ad Add checks for undefined structure elements used IEC 61131-3 source code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 365
diff changeset
  2252
  } else if (NULL == right_type) {
386
606443ffd589 Fix semantic verification of enumerated data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 367
diff changeset
  2253
    STAGE3_ERROR(symbol->r_exp, symbol->r_exp, "Could not determine data type of expression (undefined variable, constant, or structure element?).\n");
367
6d94128ba5ad Add checks for undefined structure elements used IEC 61131-3 source code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 365
diff changeset
  2254
  } else if (!is_valid_assignment(left_type, right_type))
6d94128ba5ad Add checks for undefined structure elements used IEC 61131-3 source code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 365
diff changeset
  2255
    STAGE3_ERROR(symbol, symbol, "data type mismatch in assignment statement!\n");
6d94128ba5ad Add checks for undefined structure elements used IEC 61131-3 source code being compiled.
Mario de Sousa <msousa@fe.up.pt>
parents: 365
diff changeset
  2256
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2257
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2258
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2259
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2260
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2261
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2262
/*****************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2263
/* B 3.2.2 Subprogram Control Statements */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2264
/*****************************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2265
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2266
/*  RETURN */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2267
// SYM_REF0(return_statement_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2268
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2269
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2270
/* fb_name '(' [param_assignment_list] ')' */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2271
/* param_assignment_list -> may be NULL ! */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2272
// SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2273
void *visit_expression_type_c::visit(fb_invocation_c *symbol) {
321
a96399ab57c2 Add better comments, and change name of functions to clarify what they do.
Mario de Sousa <msousa@fe.up.pt>
parents: 319
diff changeset
  2274
  symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2275
    /* The following should never occur. The function block must be defined, 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2276
     * and the FB type being called MUST be in the symtable... 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2277
     * This was all already checked at stage 2!
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2278
     */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2279
  if (NULL == fb_decl) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2280
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2281
  /* now check the semantics of the fb call... */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2282
  /* If the syntax parser is working correctly, exactly one of the 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2283
   * following two symbols will be NULL, while the other is != NULL.
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2284
   */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2285
  if (symbol->   formal_param_list != NULL) check_formal_call   (symbol, fb_decl);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2286
  if (symbol->nonformal_param_list != NULL) check_nonformal_call(symbol, fb_decl);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2287
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2288
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2289
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2290
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2291
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2292
#if 0
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2293
/* helper symbol for fb_invocation */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2294
/* param_assignment_list ',' param_assignment */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2295
SYM_LIST(param_assignment_list_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2296
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2297
/*  variable_name ASSIGN expression */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2298
SYM_REF2(input_variable_param_assignment_c, variable_name, expression)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2299
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2300
/* [NOT] variable_name '=>' variable */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2301
SYM_REF3(output_variable_param_assignment_c, not_param, variable_name, variable)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2302
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2303
/* helper CLASS for output_variable_param_assignment */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2304
SYM_REF0(not_paramassign_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2305
#endif
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2306
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2307
/********************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2308
/* B 3.2.3 Selection Statements */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2309
/********************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2310
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2311
/* IF expression THEN statement_list elseif_statement_list ELSE statement_list END_IF */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2312
// SYM_REF4(if_statement_c, expression, statement_list, elseif_statement_list, else_statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2313
void *visit_expression_type_c::visit(if_statement_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2314
  symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
260
70dfd493e639 Error messages (stage3) now better identify the location of the error.
Mario de Sousa <msousa@fe.up.pt>
parents: 259
diff changeset
  2315
  if (!is_BOOL_type(expr_type)) STAGE3_ERROR(symbol->expression,symbol->expression,"IF conditional expression is not of boolean type.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2316
  if (NULL != symbol->statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2317
    symbol->statement_list->accept(*this); 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2318
  if (NULL != symbol->elseif_statement_list)  
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2319
    symbol->elseif_statement_list->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2320
  if (NULL != symbol->else_statement_list)  
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2321
    symbol->else_statement_list->accept(*this);  
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2322
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2323
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2324
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2325
/* helper symbol for if_statement */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2326
// SYM_LIST(elseif_statement_list_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2327
// void *visit_expression_type_c::visit(elseif_statement_list_c *symbol) { }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2328
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2329
/* helper symbol for elseif_statement_list */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2330
/* ELSIF expression THEN statement_list    */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2331
// SYM_REF2(elseif_statement_c, expression, statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2332
void *visit_expression_type_c::visit(elseif_statement_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2333
  symbol_c *elseif_expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
260
70dfd493e639 Error messages (stage3) now better identify the location of the error.
Mario de Sousa <msousa@fe.up.pt>
parents: 259
diff changeset
  2334
  if(!is_BOOL_type(elseif_expr_type)) STAGE3_ERROR(symbol->expression,symbol->expression,"ELSIF conditional expression is not of boolean type.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2335
  if (NULL != symbol->statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2336
    symbol->statement_list->accept(*this); 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2337
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2338
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2339
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2340
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2341
/* CASE expression OF case_element_list ELSE statement_list END_CASE */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2342
// SYM_REF3(case_statement_c, expression, case_element_list, statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2343
void *visit_expression_type_c::visit(case_statement_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2344
  case_expression_type = base_type((symbol_c*)symbol->expression->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2345
  if (NULL != case_expression_type) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2346
    if (NULL != symbol->case_element_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2347
      symbol->case_element_list->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2348
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2349
  if (NULL != symbol->statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2350
    symbol->statement_list->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2351
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2352
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2353
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2354
#if 0
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2355
/* helper symbol for case_statement */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2356
// SYM_LIST(case_element_list_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2357
// void *visit_expression_type_c::visit(case_element_list_c *symbol);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2358
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2359
/*  case_list ':' statement_list */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2360
// SYM_REF2(case_element_c, case_list, statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2361
void *visit_expression_type_c::visit(case_element_c *symbol);  
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2362
#endif
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2363
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2364
// SYM_LIST(case_list_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2365
void *visit_expression_type_c::visit(case_list_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2366
  symbol_c *element_type;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2367
  for(int i = 0; i < symbol->n; i++) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2368
    element_type = (symbol_c *)symbol->elements[i]->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2369
    if (NULL == element_type) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2370
      STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Case list element has undefined data type.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2371
    } else {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2372
      element_type = base_type(element_type);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2373
      if (NULL != element_type){
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2374
        /* The CASE value is only used for comparison (and not assingment), so we only check for compatibility! */ 
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2375
        if (!is_compatible_type(case_expression_type, element_type))
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2376
          STAGE3_ERROR(symbol->elements[i], symbol->elements[i], "Invalid data type of case list element.");
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2377
      }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2378
    }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2379
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2380
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2381
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2382
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2383
/********************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2384
/* B 3.2.4 Iteration Statements */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2385
/********************************/
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2386
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2387
/*  FOR control_variable ASSIGN expression TO expression [BY expression] DO statement_list END_FOR */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2388
// SYM_REF5(for_statement_c, control_variable, beg_expression, end_expression, by_expression, statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2389
void *visit_expression_type_c::visit(for_statement_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2390
  symbol_c *var_type = (symbol_c*)symbol->control_variable->accept(*this);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2391
  if (NULL == var_type) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2392
  var_type = base_type(var_type);
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2393
  if (NULL == var_type) ERROR;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2394
  // ASSIGN
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2395
  symbol_c *beg_expr_type = base_type((symbol_c*)symbol->beg_expression->accept(*this));
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2396
  if (NULL != beg_expr_type) {
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2397
    /* The BEG value is assigned to the variable, so we check for assignment validity! */ 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2398
    if(!is_valid_assignment(var_type, beg_expr_type)) 
260
70dfd493e639 Error messages (stage3) now better identify the location of the error.
Mario de Sousa <msousa@fe.up.pt>
parents: 259
diff changeset
  2399
      STAGE3_ERROR(symbol->beg_expression, symbol->beg_expression, "Data type mismatch between control variable and initial value.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2400
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2401
  // TO
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2402
  symbol_c *end_expr_type = base_type((symbol_c*)symbol->end_expression->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2403
  if (NULL != end_expr_type) { 
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2404
    /* The TO value is only used for comparison, so we only check for compatibility! */ 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2405
    if(!is_compatible_type(var_type, end_expr_type)) 
260
70dfd493e639 Error messages (stage3) now better identify the location of the error.
Mario de Sousa <msousa@fe.up.pt>
parents: 259
diff changeset
  2406
      STAGE3_ERROR(symbol->end_expression, symbol->end_expression, "Data type mismatch between control variable and final value.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2407
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2408
  // BY
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2409
  if(symbol->by_expression != NULL) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2410
    symbol_c *by_expr_type = base_type((symbol_c*)symbol->by_expression->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2411
    if (NULL != end_expr_type) {   
257
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2412
      /* The BY value is used in an expression (add, sub, ...), so we only check for compatibility! */ 
90782e241346 Huge change.
Mario de Sousa <msousa@fe.up.pt>
parents: 204
diff changeset
  2413
      if(!is_compatible_type(var_type, by_expr_type)) 
260
70dfd493e639 Error messages (stage3) now better identify the location of the error.
Mario de Sousa <msousa@fe.up.pt>
parents: 259
diff changeset
  2414
        STAGE3_ERROR(symbol->by_expression, symbol->by_expression, "Data type mismatch between control variable and BY value.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2415
    }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2416
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2417
  // DO
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2418
  if (NULL != symbol->statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2419
    symbol->statement_list->accept(*this); 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2420
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2421
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2422
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2423
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2424
/*  WHILE expression DO statement_list END_WHILE */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2425
// SYM_REF2(while_statement_c, expression, statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2426
void *visit_expression_type_c::visit(while_statement_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2427
  symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2428
  if (NULL != expr_type) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2429
    if(!is_BOOL_type(expr_type)) 
260
70dfd493e639 Error messages (stage3) now better identify the location of the error.
Mario de Sousa <msousa@fe.up.pt>
parents: 259
diff changeset
  2430
      STAGE3_ERROR(symbol->expression,symbol->expression,"WHILE conditional expression is not of boolean type.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2431
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2432
 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2433
  if (NULL != symbol->statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2434
    symbol->statement_list->accept(*this); 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2435
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2436
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2437
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2438
/*  REPEAT statement_list UNTIL expression END_REPEAT */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2439
// SYM_REF2(repeat_statement_c, statement_list, expression)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2440
void *visit_expression_type_c::visit(repeat_statement_c *symbol) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2441
  if (NULL != symbol->statement_list)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2442
    symbol->statement_list->accept(*this); 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2443
 
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2444
  symbol_c *expr_type = base_type((symbol_c*)symbol->expression->accept(*this));
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2445
  if (NULL != expr_type) {
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2446
    if(!is_BOOL_type(expr_type)) 
260
70dfd493e639 Error messages (stage3) now better identify the location of the error.
Mario de Sousa <msousa@fe.up.pt>
parents: 259
diff changeset
  2447
      STAGE3_ERROR(symbol->expression,symbol->expression,"REPEAT conditional expression is not of boolean type.");
204
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2448
  }
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2449
  return NULL;
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2450
}
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2451
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2452
/*  EXIT */
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2453
// SYM_REF0(exit_statement_c)
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2454
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2455
8ffa211b7f9a Adding missing Stage3 files.
Catarina Boucinha <ccb@fe.up.pt>
parents:
diff changeset
  2456