stage3/print_datatypes_error.cc
author Mario de Sousa <msousa@fe.up.pt>
Fri, 20 Apr 2018 17:38:09 +0100
changeset 1071 7fd69f29320a
parent 1047 34b733cb6641
permissions -rw-r--r--
fix backup/restore functions: now also backup/restore programs instantiated to run inside tasks.
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     1
/*
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     3
 *
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     4
 *  Copyright (C) 2009-2011  Mario de Sousa (msousa@fe.up.pt)
486
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
     5
 *  Copyright (C) 2011-2012 Manuele Conti (manuele.conti@sirius-es.it)
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
     6
 *  Copyright (C) 2011-2012 Matteo Facchinetti (matteo.facchinetti@sirius-es.it)
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     7
 *
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     8
 *  This program is free software: you can redistribute it and/or modify
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     9
 *  it under the terms of the GNU General Public License as published by
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    10
 *  the Free Software Foundation, either version 3 of the License, or
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    11
 *  (at your option) any later version.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    12
 *
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    13
 *  This program is distributed in the hope that it will be useful,
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    16
 *  GNU General Public License for more details.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    17
 *
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    20
 *
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    21
 *
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    22
 * This code is made available on the understanding that it will not be
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    23
 * used in safety-critical situations without a full and competent review.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    24
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    25
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    26
/*
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    27
 * An IEC 61131-3 compiler.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    28
 *
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    29
 * Based on the
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    30
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    31
 *
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    32
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    33
552
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 551
diff changeset
    34
/* NOTE: The algorithm implemented here assumes that the symbol_c.candidate_datatype, and the symbol_c.datatype 
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 551
diff changeset
    35
 *       annotations have already been apropriately filled in!
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 551
diff changeset
    36
 *       BEFORE running this visitor, be sure to CALL the fill_candidate_datatypes_c, and the narrow_candidate_datatypes_c visitors!
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 551
diff changeset
    37
 */
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 551
diff changeset
    38
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    39
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    40
/*
552
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 551
diff changeset
    41
 *  By analysing the candidate datatype lists, as well as the chosen datatype for each expression, determine
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 551
diff changeset
    42
 *  if an datatype error has been found, and if so, print out an error message.
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    43
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    44
552
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 551
diff changeset
    45
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    46
#include "print_datatypes_error.hh"
434
c1278e52bcbc Move elementary_c::to_string() to datatype_functions.cc/hh
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
    47
#include "datatype_functions.hh"
c1278e52bcbc Move elementary_c::to_string() to datatype_functions.cc/hh
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
    48
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    49
#include <typeinfo>
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    50
#include <list>
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    51
#include <string>
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    52
#include <string.h>
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    53
#include <strings.h>
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    54
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    55
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    56
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    57
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    58
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    59
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    60
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    61
#define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    62
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    63
#define STAGE3_ERROR(error_level, symbol1, symbol2, ...) {                                                                  \
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    64
  if (current_display_error_level >= error_level) {                                                                         \
458
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    65
    fprintf(stderr, "%s:%d-%d..%d-%d: error: ",                                                                             \
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    66
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    67
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    68
    fprintf(stderr, __VA_ARGS__);                                                                                           \
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    69
    fprintf(stderr, "\n");                                                                                                  \
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    70
    il_error = true;                                                                                                        \
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
    71
    error_count++;                                                                                                     \
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    72
  }                                                                                                                         \
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    73
}  
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    74
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    75
458
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    76
#define STAGE3_WARNING(symbol1, symbol2, ...) {                                                                             \
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    77
    fprintf(stderr, "%s:%d-%d..%d-%d: warning: ",                                                                           \
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    78
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,\
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    79
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column);\
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    80
    fprintf(stderr, __VA_ARGS__);                                                                                           \
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    81
    fprintf(stderr, "\n");                                                                                                  \
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    82
    warning_found = true;                                                                                                   \
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    83
}  
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    84
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    85
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    86
/* set to 1 to see debug info during execution */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    87
static int debug = 0;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    88
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    89
print_datatypes_error_c::print_datatypes_error_c(symbol_c *ignore) {
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
    90
	error_count = 0;
458
587884880be6 iAdd warning for deprecated operations.
Conti Manuele <conti.ma@alice.it>
parents: 457
diff changeset
    91
	warning_found = false;
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
    92
	current_display_error_level = error_level_default;
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    93
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    94
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    95
print_datatypes_error_c::~print_datatypes_error_c(void) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    96
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    97
510
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
    98
int print_datatypes_error_c::get_error_count() {
9317e04c1dde Fixing check for assignment to output variables.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
    99
	return error_count;
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   100
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   101
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   102
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   103
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   104
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   105
689
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   106
/* Verify if the datatypes of all symbols in the vector are valid and equal!  */
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   107
static bool are_all_datatypes_equal(std::vector <symbol_c *> &symbol_vect) {
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   108
	if (symbol_vect.size() <= 0) return false;
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   109
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   110
	bool res = get_datatype_info_c::is_type_valid(symbol_vect[0]->datatype);
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   111
	for (unsigned int i = 1; i < symbol_vect.size(); i++)
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   112
		res &= get_datatype_info_c::is_type_equal(symbol_vect[i-1]->datatype, symbol_vect[i]->datatype);	
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   113
	return res;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   114
}
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   115
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   116
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   117
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   118
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   119
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   120
/*
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   121
typedef struct {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   122
  symbol_c *function_name,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   123
  symbol_c *nonformal_operand_list,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   124
  symbol_c *   formal_operand_list,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   125
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   126
  std::vector <symbol_c *> &candidate_functions,  
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   127
  symbol_c &*called_function_declaration,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   128
  int      &extensible_param_count
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   129
} generic_function_call_t;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   130
*/
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   131
void print_datatypes_error_c::handle_function_invocation(symbol_c *fcall, generic_function_call_t fcall_data) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   132
	symbol_c *param_value, *param_name;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   133
	function_call_param_iterator_c fcp_iterator(fcall);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   134
	bool function_invocation_error = false;
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   135
	const char *POU_str = NULL;
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   136
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   137
	if (generic_function_call_t::POU_FB       == fcall_data.POU_type)  POU_str = "FB";
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   138
	if (generic_function_call_t::POU_function == fcall_data.POU_type)  POU_str = "function";
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   139
	if (NULL == POU_str) ERROR;
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   140
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   141
	if ((NULL != fcall_data.formal_operand_list) && (NULL != fcall_data.nonformal_operand_list)) 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   142
		ERROR;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   143
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   144
	symbol_c *f_decl = fcall_data.called_function_declaration;
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   145
	if ((NULL == f_decl) && (generic_function_call_t::POU_FB ==fcall_data.POU_type)) {
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   146
		/* Due to the way the syntax analysis is buit (i.e. stage 2), this should never occur. */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   147
		/* I.e., a FB invocation using an undefined FB variable is not possible in the current implementation of stage 2. */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   148
		ERROR;
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   149
	}
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   150
	if (NULL == f_decl) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   151
		/* we now try to find any function declaration with the same name, just so we can provide some relevant error messages */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   152
		function_symtable_t::iterator lower = function_symtable.lower_bound(fcall_data.function_name);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   153
		if (lower == function_symtable.end()) ERROR;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   154
		f_decl = function_symtable.get_value(lower);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   155
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   156
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   157
	if (NULL != fcall_data.formal_operand_list) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   158
		fcall_data.formal_operand_list->accept(*this);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   159
		if (NULL != f_decl) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   160
			function_param_iterator_c fp_iterator(f_decl);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   161
			while ((param_name = fcp_iterator.next_f()) != NULL) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   162
				param_value = fcp_iterator.get_current_value();
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   163
				
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   164
				/* Check if there are duplicate parameter values */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   165
				if(fcp_iterator.search_f(param_name) != param_value) {
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   166
					function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   167
					STAGE3_ERROR(0, param_name, param_name, "Duplicate parameter '%s' when invoking %s '%s'", ((token_c *)param_name)->value, POU_str, ((token_c *)fcall_data.function_name)->value);
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   168
					continue; /* jump to next parameter */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   169
				}
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   170
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   171
				/* Find the corresponding parameter in function declaration */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   172
				if (NULL == fp_iterator.search(param_name)) {
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   173
					function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   174
					STAGE3_ERROR(0, param_name, param_name, "Invalid parameter '%s' when invoking %s '%s'", ((token_c *)param_name)->value, POU_str, ((token_c *)fcall_data.function_name)->value);
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   175
					continue; /* jump to next parameter */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   176
				} 
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   177
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   178
				/* check whether direction (IN, OUT, IN_OUT) and assignment types (:= , =>) are compatible !!! */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   179
				/* Obtaining the assignment direction:  := (assign_in) or => (assign_out) */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   180
				function_call_param_iterator_c::assign_direction_t call_param_dir = fcp_iterator.get_assign_direction();
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   181
				/* Get the parameter direction: IN, OUT, IN_OUT */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   182
				function_param_iterator_c::param_direction_t param_dir = fp_iterator.param_direction();
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   183
				if          (function_call_param_iterator_c::assign_in  == call_param_dir) {
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   184
					if ((function_param_iterator_c::direction_in    != param_dir) &&
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   185
					    (function_param_iterator_c::direction_inout != param_dir)) {
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   186
						function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   187
						STAGE3_ERROR(0, param_name, param_name, "Invalid assignment syntax ':=' used for parameter '%s', when invoking %s '%s'", ((token_c *)param_name)->value, POU_str, ((token_c *)fcall_data.function_name)->value);
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   188
						continue; /* jump to next parameter */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   189
					}
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   190
				} else if   (function_call_param_iterator_c::assign_out == call_param_dir) {
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   191
					if ((function_param_iterator_c::direction_out   != param_dir)) {
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   192
						function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   193
						STAGE3_ERROR(0, param_name, param_name, "Invalid assignment syntax '=>' used for parameter '%s', when invoking %s '%s'", ((token_c *)param_name)->value, POU_str, ((token_c *)fcall_data.function_name)->value);
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   194
						continue; /* jump to next parameter */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   195
					}
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   196
				} else ERROR;
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   197
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   198
				if (!get_datatype_info_c::is_type_valid(param_value->datatype)) {
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   199
					function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   200
					STAGE3_ERROR(0, param_value, param_value, "Data type incompatibility between parameter '%s' and value being passed, when invoking %s '%s'", ((token_c *)param_name)->value, POU_str, ((token_c *)fcall_data.function_name)->value);
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   201
					continue; /* jump to next parameter */
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   202
				}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   203
			}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   204
		}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   205
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   206
	if (NULL != fcall_data.nonformal_operand_list) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   207
		if (f_decl)
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   208
			for (int i = 1; (param_value = fcp_iterator.next_nf()) != NULL; i++) {
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   209
		  		/* TODO: verify if it is lvalue when INOUT or OUTPUT parameters! */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   210
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   211
				/* This handle_function_invocation() will be called to handle IL function calls, where the first parameter comes from the previous IL instruction.
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   212
				 * In this case, the previous IL instruction will be artifically (and temporarily) added to the begining ot the parameter list
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   213
				 * so we (in this function) can handle this situation like all the other function calls.
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   214
				 * However, 
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   215
				 *     a) if NO previous IL function exists, then we get a fake previous IL function, with no location data (i.e. not found anywhere in the source code.
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   216
				 *     b) the function call may actually have several prev IL instructions (if several JMP instructions jump directly to the il function call).
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   217
				 * In order to handle these situations gracefully, we first check whether the first parameter is really an IL istruction!
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   218
				 */
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   219
				il_instruction_c *il_instruction_symbol = dynamic_cast<il_instruction_c *>(param_value);
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   220
				if ((NULL != il_instruction_symbol) && (i == 1)) {
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   221
					/* We are in a situation where an IL function call is passed the first parameter, which is actually the previous IL instruction */
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   222
					/* However, this is really a fake previous il instruction (see visit(il_instruction_c *) )
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   223
					 * We will iterate through all the real previous IL instructions, and analyse each of them one by one */
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   224
					if (il_instruction_symbol->prev_il_instruction.size() == 0) {
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   225
						function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   226
						STAGE3_ERROR(0, fcall, fcall, "No available data to pass to first parameter of IL function %s. Missing a previous LD instruction?", ((token_c *)fcall_data.function_name)->value);
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   227
					}
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   228
#if 0
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   229
					/* NOTE: We currently comment out this code...
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   230
					 * This does not currently work, since the narrow operation is currently done on the intersection 
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   231
					 * of all the previous IL instructions, so we currently either accept them all, or none at all.
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   232
					 * In order to be able to produce these user freindly error messages, we will need to update the 
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   233
					 * narrow algorithm. We leave this untill somebody aks for it...
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   234
					 * So, for now, we simply comment out this code.
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   235
					 */
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   236
					for (unsigned int p = 0; p < il_instruction_symbol->prev_il_instruction.size(); p++) {
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   237
						symbol_c *value = il_instruction_symbol->prev_il_instruction[p];  
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
   238
						if (!get_datatype_info_c::is_type_valid(value->datatype)) {
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   239
							function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   240
							STAGE3_ERROR(0, fcall, fcall, "Data type incompatibility for value passed to first parameter when invoking function '%s'", ((token_c *)fcall_data.function_name)->value);
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   241
							STAGE3_ERROR(0, value, value, "This is the IL instruction producing the incompatible data type to first parameter of function '%s'", ((token_c *)fcall_data.function_name)->value);
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   242
						}
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   243
					}
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   244
#else
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
   245
					if (!get_datatype_info_c::is_type_valid(il_instruction_symbol->datatype)) {
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   246
						function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   247
						STAGE3_ERROR(0, fcall, fcall, "Data type incompatibility between value in IL 'accumulator' and first parameter of function '%s'", ((token_c *)fcall_data.function_name)->value);
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   248
					}
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   249
#endif
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   250
					if (function_invocation_error)
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   251
						/* when handling a IL function call, and an error is found in the first parameter, then we bug out and do not print out any more error messages. */
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   252
						return;
847
079ab7d4b728 Recursively check the datatype compatibility of values/expressions passed in function/FB invocations.
mjsousa
parents: 841
diff changeset
   253
				} else {
079ab7d4b728 Recursively check the datatype compatibility of values/expressions passed in function/FB invocations.
mjsousa
parents: 841
diff changeset
   254
					if (!get_datatype_info_c::is_type_valid(param_value->datatype)) {
079ab7d4b728 Recursively check the datatype compatibility of values/expressions passed in function/FB invocations.
mjsousa
parents: 841
diff changeset
   255
						function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   256
						STAGE3_ERROR(0, param_value, param_value, "Data type incompatibility for value passed in position %d when invoking %s '%s'", i, POU_str, ((token_c *)fcall_data.function_name)->value);
847
079ab7d4b728 Recursively check the datatype compatibility of values/expressions passed in function/FB invocations.
mjsousa
parents: 841
diff changeset
   257
					}
079ab7d4b728 Recursively check the datatype compatibility of values/expressions passed in function/FB invocations.
mjsousa
parents: 841
diff changeset
   258
					param_value->accept(*this);
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   259
				}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   260
			}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   261
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   262
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   263
	if (NULL == fcall_data.called_function_declaration) {
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   264
		function_invocation_error = true;
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   265
		STAGE3_ERROR(0, fcall, fcall, "Unable to resolve which overloaded %s '%s' is being invoked.", POU_str, ((token_c *)fcall_data.function_name)->value);
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   266
	}
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   267
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   268
	if (function_invocation_error) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   269
		/* No compatible function exists */
958
7474d2cd1d6e Add a new pou_typename_c object to the AST to store references to previously declared Functions, FB, and Programs.
mjsousa
parents: 936
diff changeset
   270
		STAGE3_ERROR(2, fcall, fcall, "Invalid parameters when invoking %s '%s'", POU_str, ((token_c *)fcall_data.function_name)->value);
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   271
	} 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   272
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   273
	return;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   274
}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   275
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   276
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   277
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   278
void *print_datatypes_error_c::handle_implicit_il_fb_invocation(const char *param_name, symbol_c *il_operator, symbol_c *called_fb_declaration) {
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   279
	if (NULL == il_operand) {
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   280
		STAGE3_ERROR(0, il_operator, il_operator, "Missing operand for FB call operator '%s'.", param_name);
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   281
		return NULL;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   282
	}
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   283
	// il_operand->accept(*this);  // NOT required. The il_simple_operation_c already visits it!!
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   284
	
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   285
	if (NULL == called_fb_declaration) {
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   286
		STAGE3_ERROR(0, il_operator, il_operand, "Invalid FB call: operand is not a FB instance.");
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   287
		return NULL;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   288
	}
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   289
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   290
	if (fake_prev_il_instruction->prev_il_instruction.empty()) {
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   291
		STAGE3_ERROR(0, il_operator, il_operand, "FB invocation operator '%s' must be preceded by a 'LD' (or equivalent) operator.", param_name);	
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   292
		return NULL;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   293
	}
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   294
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   295
	/* Find the corresponding parameter in function declaration */
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   296
	function_param_iterator_c fp_iterator(called_fb_declaration);
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   297
	if (NULL == fp_iterator.search(param_name)) {
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   298
		/* TODO: must also check whther it is an IN parameter!! */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   299
		/* NOTE: although all standard FBs have the implicit FB calls defined as input parameters
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   300
		*        (i.e., for all standard FBs, CLK, PT, IN, CU, CD, S1, R1, etc... is always an input parameter)
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   301
		*        if a non-standard (i.e. a FB not defined in the standard library) FB is being called, then
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   302
		*        this (CLK, PT, IN, CU, ...) parameter may just have been defined as OUT or INOUT,
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   303
		*        which will not work for an implicit FB call!
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   304
		*/
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   305
		STAGE3_ERROR(0, il_operator, il_operand, "FB called by '%s' operator does not have a parameter named '%s'", param_name, param_name);	
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   306
		return NULL;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   307
	}
689
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   308
	if (!are_all_datatypes_equal(fake_prev_il_instruction->prev_il_instruction)) {
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   309
		STAGE3_ERROR(0, il_operator, il_operand, "Data type incompatibility between parameter '%s' and value being passed.", param_name);
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   310
		return NULL;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   311
	}
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   312
	
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   313
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   314
	/* NOTE: The error_level currently being used for errors in variables/constants etc... is rather high.
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   315
	 *       However, in the case of an implicit FB call, if the datatype of the operand == NULL, this may be
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   316
	 *       the __only__ indication of an error! So we test it here again, to make sure thtis error will really
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   317
	 *       be printed out!
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   318
	 */
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   319
	if (!get_datatype_info_c::is_type_valid(il_operand->datatype)) {
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   320
		/* Note: the case of (NULL == fb_declaration) was already caught above! */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   321
// 		if (NULL != fb_declaration) {
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   322
			STAGE3_ERROR(0, il_operator, il_operator, "Invalid FB call: Datatype incompatibility between the FB's '%s' parameter and value being passed, or paramater '%s' is not a 'VAR_INPUT' parameter.", param_name, param_name);
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   323
			return NULL;
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   324
// 		}
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   325
	}
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   326
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   327
	return NULL;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   328
}
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   329
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   330
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   331
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   332
/* B 1.2 - Constants */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   333
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   334
/******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   335
/* B 1.2.1 - Numeric Literals */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   336
/******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   337
void *print_datatypes_error_c::visit(real_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   338
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   339
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   340
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   341
		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   342
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   343
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   344
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   345
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   346
void *print_datatypes_error_c::visit(integer_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   347
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   348
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   349
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   350
		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   351
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   352
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   353
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   354
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   355
void *print_datatypes_error_c::visit(neg_real_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   356
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   357
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   358
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   359
		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   360
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   361
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   362
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   363
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   364
void *print_datatypes_error_c::visit(neg_integer_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   365
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   366
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   367
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   368
		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   369
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   370
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   371
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   372
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   373
void *print_datatypes_error_c::visit(binary_integer_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   374
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   375
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   376
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   377
		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   378
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   379
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   380
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   381
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   382
void *print_datatypes_error_c::visit(octal_integer_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   383
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   384
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   385
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   386
		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   387
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   388
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   389
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   390
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   391
void *print_datatypes_error_c::visit(hex_integer_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   392
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   393
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   394
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   395
		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   396
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   397
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   398
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   399
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   400
void *print_datatypes_error_c::visit(integer_literal_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   401
	if (symbol->candidate_datatypes.size() == 0) {
778
44e02a88f1e7 moved class to obtain datatype name (in char *) to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 732
diff changeset
   402
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   403
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   404
		STAGE3_ERROR(4, symbol, symbol, "ANY_INT data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   405
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   406
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   407
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   408
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   409
void *print_datatypes_error_c::visit(real_literal_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   410
	if (symbol->candidate_datatypes.size() == 0) {
778
44e02a88f1e7 moved class to obtain datatype name (in char *) to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 732
diff changeset
   411
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   412
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   413
		STAGE3_ERROR(4, symbol, symbol, "ANY_REAL data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   414
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   415
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   416
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   418
void *print_datatypes_error_c::visit(bit_string_literal_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   419
	if (symbol->candidate_datatypes.size() == 0) {
778
44e02a88f1e7 moved class to obtain datatype name (in char *) to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 732
diff changeset
   420
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   421
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   422
		STAGE3_ERROR(4, symbol, symbol, "ANY_BIT data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   423
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   424
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   425
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   426
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   427
void *print_datatypes_error_c::visit(boolean_literal_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   428
	if (symbol->candidate_datatypes.size() == 0) {
778
44e02a88f1e7 moved class to obtain datatype name (in char *) to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 732
diff changeset
   429
		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for %s data type.", get_datatype_info_c::get_id_str(symbol->type));
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   430
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   431
		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   432
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   433
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   434
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   435
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   436
void *print_datatypes_error_c::visit(boolean_true_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   437
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   438
		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   439
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   440
		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   441
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   442
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   443
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   444
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   445
void *print_datatypes_error_c::visit(boolean_false_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   446
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   447
		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   448
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   449
		STAGE3_ERROR(4, symbol, symbol, "ANY_BOOL data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   450
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   451
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   452
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   453
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   454
/*******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   455
/* B.1.2.2   Character Strings */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   456
/*******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   457
void *print_datatypes_error_c::visit(double_byte_character_string_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   458
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   459
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for WSTRING data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   460
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   461
		STAGE3_ERROR(4, symbol, symbol, "WSTRING data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   462
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   463
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   464
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   465
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   466
void *print_datatypes_error_c::visit(single_byte_character_string_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   467
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   468
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for STRING data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   469
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   470
		STAGE3_ERROR(4, symbol, symbol, "STRING data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   471
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   472
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   473
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   474
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   475
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   476
/* B 1.2.3 - Time Literals */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   477
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   478
/************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   479
/* B 1.2.3.1 - Duration */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   480
/************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   481
void *print_datatypes_error_c::visit(duration_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   482
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   483
		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TIME data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   484
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   485
		STAGE3_ERROR(4, symbol, symbol, "TIME data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   486
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   487
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   488
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   489
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   490
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   491
/* B 1.2.3.2 - Time of day and Date */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   492
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   493
void *print_datatypes_error_c::visit(time_of_day_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   494
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   495
		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TOD data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   496
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   497
		STAGE3_ERROR(4, symbol, symbol, "TOD data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   498
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   499
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   500
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   501
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   502
void *print_datatypes_error_c::visit(date_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   503
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   504
		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DATE data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   505
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   506
		STAGE3_ERROR(4, symbol, symbol, "DATE data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   507
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   508
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   509
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   510
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   511
void *print_datatypes_error_c::visit(date_and_time_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   512
	if (symbol->candidate_datatypes.size() == 0) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   513
		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DT data type.");
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   514
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   515
		STAGE3_ERROR(4, symbol, symbol, "DT data type not valid in this location.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   516
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   517
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   518
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   519
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   520
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   521
/* B 1.3 - Data types */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   522
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   523
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   524
/* B 1.3.3 - Derived data types */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   525
/********************************/
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   526
void *print_datatypes_error_c::visit(simple_spec_init_c *symbol) {
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
   527
	if (!get_datatype_info_c::is_type_valid(symbol->simple_specification->datatype)) {
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   528
		STAGE3_ERROR(0, symbol->simple_specification, symbol->simple_specification, "Invalid data type.");
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   529
	} else if (NULL != symbol->constant) {
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
   530
		if (!get_datatype_info_c::is_type_valid(symbol->constant->datatype))
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   531
			STAGE3_ERROR(0, symbol->constant, symbol->constant, "Initial value has incompatible data type.");
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
   532
	} else if (!get_datatype_info_c::is_type_valid(symbol->datatype)) {
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   533
		ERROR; /* If we have an error here, then we must also have an error in one of
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   534
		        * the two previous tests. If we reach this point, some strange error is ocurring!
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   535
			*/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   536
	}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   537
	return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   538
}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   539
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   540
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   541
void *print_datatypes_error_c::visit(enumerated_value_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   542
	if (symbol->candidate_datatypes.size() == 0)
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   543
		STAGE3_ERROR(0, symbol, symbol, "Ambiguous enumerate value or Variable not declared in this scope.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   544
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   545
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   546
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   547
1047
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   548
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   549
void *print_datatypes_error_c::visit(structure_element_initialization_c *symbol) {
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   550
	symbol->value->accept(*this);
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   551
	if (!get_datatype_info_c::is_type_valid(symbol->datatype))
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   552
		STAGE3_ERROR(0, symbol, symbol, "Initialization element identifier (%s) is not declared in referenced structure/FB scope, or is set to value of incompatible datatype.", 
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   553
			                        symbol->structure_element_name->token->value);
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   554
	return NULL;
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   555
}
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   556
34b733cb6641 Do datatype checking of initial values for structures and FBs, and print error messages when compiling erroneuos source code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   557
    
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   558
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   559
/* B 1.4 - Variables */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   560
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   561
void *print_datatypes_error_c::visit(symbolic_variable_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   562
	if (symbol->candidate_datatypes.size() == 0)
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   563
		STAGE3_ERROR(0, symbol, symbol, "Variable not declared in this scope.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   564
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   565
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   566
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   567
/********************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   568
/* B 1.4.1 - Directly Represented Variables */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   569
/********************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   570
void *print_datatypes_error_c::visit(direct_variable_c *symbol) {
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   571
	if (symbol->candidate_datatypes.size() == 0) ERROR;
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
   572
	if (!get_datatype_info_c::is_type_valid(symbol->datatype))
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   573
		STAGE3_ERROR(4, symbol, symbol, "Direct variable has incompatible data type with expression.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   574
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   575
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   576
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   577
/*************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   578
/* B 1.4.2 - Multi-element variables */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   579
/*************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   580
/*  subscripted_variable '[' subscript_list ']' */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   581
// SYM_REF2(array_variable_c, subscripted_variable, subscript_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   582
void *print_datatypes_error_c::visit(array_variable_c *symbol) {
827
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   583
	/* the subscripted variable may be a structure or another array variable, that must also be visisted! */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   584
	/* Please read the comments in the array_variable_c and structured_variable_c visitors in the fill_candidate_datatypes.cc file! */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   585
	symbol->subscripted_variable->accept(*this); 
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   586
	
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   587
	if (symbol->candidate_datatypes.size() == 0)
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   588
		STAGE3_ERROR(0, symbol, symbol, "Array variable not declared in this scope.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   589
	
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   590
	/* recursively call the subscript list to print any errors in the expressions used in the subscript...*/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   591
	symbol->subscript_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   592
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   593
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   594
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   595
/* subscript_list ',' subscript */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   596
// SYM_LIST(subscript_list_c)
549
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   597
void *print_datatypes_error_c::visit(subscript_list_c *symbol) {
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   598
	for (int i = 0; i < symbol->n; i++) {
550
322f063daa9f Fix the previous commit: check for errors in expressions used as subscripts.
mjsousa <msousa@fe.up.pt>
parents: 549
diff changeset
   599
		int start_error_count = error_count;
1041
56ebe2a31b5b Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents: 995
diff changeset
   600
		symbol->get_element(i)->accept(*this);
551
a75e3aea98ff Fix comment.
mjsousa <msousa@fe.up.pt>
parents: 550
diff changeset
   601
		/* The following error message will only get printed if the current_display_error_level is set higher than 0! */
1041
56ebe2a31b5b Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents: 995
diff changeset
   602
		if ((start_error_count == error_count) && (!get_datatype_info_c::is_type_valid(symbol->get_element(i)->datatype)))
549
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   603
			STAGE3_ERROR(0, symbol, symbol, "Invalid data type for array subscript field.");
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   604
	}
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   605
	return NULL;
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   606
}
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   607
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   608
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   609
/*  record_variable '.' field_selector */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   610
/*  WARNING: input and/or output variables of function blocks
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   611
 *           may be accessed as fields of a structured variable!
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   612
 *           Code handling a structured_variable_c must take
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   613
 *           this into account!
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   614
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   615
// SYM_REF2(structured_variable_c, record_variable, field_selector)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   616
void *print_datatypes_error_c::visit(structured_variable_c *symbol) {
827
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   617
	/* the record variable may be another structure or even an array variable, that must also be visisted! */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   618
	/* Please read the comments in the array_variable_c and structured_variable_c visitors in the fill_candidate_datatypes.cc file! */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   619
	symbol->record_variable->accept(*this);
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   620
	
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   621
	if (symbol->candidate_datatypes.size() == 0)
827
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 778
diff changeset
   622
		STAGE3_ERROR(0, symbol, symbol, "Undeclared structured (or FB) variable, or non-existant field (variable) in structure (FB).");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   623
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   624
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   625
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   626
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   627
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   628
/******************************************/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   629
/* B 1.4.3 - Declaration & Initialisation */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   630
/******************************************/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   631
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   632
/*  AT direct_variable */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   633
// SYM_REF1(location_c, direct_variable)
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   634
void *print_datatypes_error_c::visit(location_c *symbol) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   635
	symbol->direct_variable->accept(*this);
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   636
	return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   637
}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   638
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   639
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   640
/*  [variable_name] location ':' located_var_spec_init */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   641
/* variable_name -> may be NULL ! */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   642
// SYM_REF3(located_var_decl_c, variable_name, location, located_var_spec_init)
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   643
void *print_datatypes_error_c::visit(located_var_decl_c *symbol) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   644
  symbol->located_var_spec_init->accept(*this);
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   645
  /* It does not make sense to call symbol->location->accept(*this). The check is done right here if the following if() */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   646
  // symbol->location->accept(*this); 
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
   647
  if ((get_datatype_info_c::is_type_valid(symbol->located_var_spec_init->datatype)) && (!get_datatype_info_c::is_type_valid(symbol->location->datatype)))
558
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   648
    STAGE3_ERROR(0, symbol, symbol, "Bit size of data type is incompatible with bit size of location.");
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   649
  return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   650
}  
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   651
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   652
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   653
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   654
/* B 1.5 Program organization units */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   655
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   656
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   657
/* B 1.5.1 Functions */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   658
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   659
void *print_datatypes_error_c::visit(function_declaration_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   660
	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
732
f6a46e29853b Add datatype checking of enumeration data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   661
 	symbol->var_declarations_list->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   662
	if (debug) printf("Print error data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   663
	il_parenthesis_level = 0;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   664
	il_error = false;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   665
	symbol->function_body->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   666
	delete search_varfb_instance_type;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   667
	search_varfb_instance_type = NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   668
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   669
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   670
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   671
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   672
/* B 1.5.2 Function blocks */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   673
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   674
void *print_datatypes_error_c::visit(function_block_declaration_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   675
	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
732
f6a46e29853b Add datatype checking of enumeration data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   676
 	symbol->var_declarations->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   677
	if (debug) printf("Print error data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   678
	il_parenthesis_level = 0;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   679
	il_error = false;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   680
	symbol->fblock_body->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   681
	delete search_varfb_instance_type;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   682
	search_varfb_instance_type = NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   683
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   684
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   685
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   686
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   687
/* B 1.5.3 - Programs */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   688
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   689
void *print_datatypes_error_c::visit(program_declaration_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   690
	search_varfb_instance_type = new search_varfb_instance_type_c(symbol);
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   691
	symbol->var_declarations->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   692
	if (debug) printf("Print error data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   693
	il_parenthesis_level = 0;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   694
	il_error = false;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   695
	symbol->function_block_body->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   696
	delete search_varfb_instance_type;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   697
	search_varfb_instance_type = NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   698
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   699
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   700
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   701
895
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   702
/********************************************/
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   703
/* B 1.6 Sequential function chart elements */
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   704
/********************************************/
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   705
void *print_datatypes_error_c::visit(transition_condition_c *symbol) {
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   706
	if (symbol->transition_condition_il != NULL)   symbol->transition_condition_il->accept(*this);
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   707
	if (symbol->transition_condition_st != NULL)   symbol->transition_condition_st->accept(*this);
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   708
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   709
	if (!get_datatype_info_c::is_type_valid(symbol->datatype))
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   710
		STAGE3_ERROR(0, symbol, symbol, "Transition condition has invalid data type (should be BOOL).");
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   711
	return NULL;
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   712
}
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 873
diff changeset
   713
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   714
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   715
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   716
/* B 1.7 Configuration elements */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   717
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   718
void *print_datatypes_error_c::visit(configuration_declaration_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   719
	// TODO !!!
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   720
	/* for the moment we must return NULL so semantic analysis of remaining code is not interrupted! */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   721
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   722
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   723
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   724
/****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   725
/* B.2 - Language IL (Instruction List) */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   726
/****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   727
/***********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   728
/* B 2.1 Instructions and Operands */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   729
/***********************************/
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   730
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   731
// void *visit(instruction_list_c *symbol);
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   732
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   733
/* | label ':' [il_incomplete_instruction] eol_list */
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   734
// SYM_REF2(il_instruction_c, label, il_instruction)
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   735
void *print_datatypes_error_c::visit(il_instruction_c *symbol) {
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   736
	if (NULL != symbol->il_instruction) {
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   737
		il_instruction_c tmp_prev_il_instruction(NULL, NULL);
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   738
#if 0
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   739
		/* NOTE: The following is currently no longer needed. Since the following code is actually cool, 
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   740
		 * we don't delete it, but simply comment it out. It might just come in handy later on...
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   741
		 */
486
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   742
		/* When handling a il function call, this fake_prev_il_instruction may be used as a standard function call parameter, so it is important that 
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   743
		 * it contain some valid location info so error messages make sense.
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   744
		 */
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   745
		if (symbol->prev_il_instruction.size() > 0) {
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   746
			/* since we don't want to copy all that data one variable at a time, we copy it all at once */
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   747
			/* This has the advantage that, if we ever add some more data to the base symbol_c later on, we will not need to
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   748
			 * change the following line to guarantee that the data is copied correctly!
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   749
			 * However, it does have the drawback of copying more data than what we want!
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   750
			 * In order to only copy the data in the base class symbol_c, we use the tmp_symbol pointer!
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   751
			 * I (mario) have checked with a debugger, and it is working as intended!
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   752
			 */
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   753
			symbol_c *tmp_symbol1 = symbol->prev_il_instruction[0];
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   754
			symbol_c *tmp_symbol2 = &tmp_prev_il_instruction;
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   755
			*tmp_symbol2 = *tmp_symbol1;
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   756
			/* we do not want to copy the datatype variable, so we reset it to NULL */
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   757
			tmp_prev_il_instruction.datatype = NULL;
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   758
			/* We don't need to worry about the candidate_datatype list (which we don't want to copy just yet), since that will 
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   759
			 * be reset to the correct value when we call intersect_prev_candidate_datatype_lists() later on...
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   760
			 */
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   761
		}
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   762
#endif
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   763
		/* the print error algorithm will need access to the intersected candidate_datatype lists of all prev_il_instructions, as well as the 
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   764
		 * list of the prev_il_instructions.
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   765
		 * Instead of creating two 'global' (within the class) variables, we create a single il_instruction_c variable (fake_prev_il_instruction),
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   766
		 * and shove that data into this single variable.
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   767
		 */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   768
		tmp_prev_il_instruction.prev_il_instruction = symbol->prev_il_instruction;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   769
		intersect_prev_candidate_datatype_lists(&tmp_prev_il_instruction);
689
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   770
		if (are_all_datatypes_equal(symbol->prev_il_instruction))
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   771
			if (symbol->prev_il_instruction.size() > 0)
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   772
				tmp_prev_il_instruction.datatype = (symbol->prev_il_instruction[0])->datatype;
486
e22150ad75fd Fix error messages of il function calls - it now prints out location info of first parameter.
Mario de Sousa <msousa@fe.up.pt>
parents: 485
diff changeset
   773
		
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   774
		/* Tell the il_instruction the datatype that it must generate - this was chosen by the next il_instruction (remember: we are iterating backwards!) */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   775
		fake_prev_il_instruction = &tmp_prev_il_instruction;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   776
		symbol->il_instruction->accept(*this);
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   777
		fake_prev_il_instruction = NULL;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   778
	}
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   779
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   780
	return NULL;
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   781
}
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   782
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   783
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   784
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   785
void *print_datatypes_error_c::visit(il_simple_operation_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   786
	il_operand = symbol->il_operand;
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   787
	if (NULL != il_operand)     symbol->il_operand->accept(*this); /* recursive call to see whether data types are compatible */
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   788
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   789
	symbol->il_simple_operator->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   790
	il_operand = NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   791
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   792
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   793
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   794
/* | function_name [il_operand_list] */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   795
/* NOTE: The parameters 'called_function_declaration' and 'extensible_param_count' are used to pass data between the stage 3 and stage 4. */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   796
// SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; int extensible_param_count;)
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   797
void *print_datatypes_error_c::visit(il_function_call_c *symbol) {
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   798
	/* The first parameter of a non formal function call in IL will be the 'current value' (i.e. the prev_il_instruction)
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   799
	 * In order to be able to handle this without coding special cases, we will simply prepend that symbol
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   800
	 * to the il_operand_list, and remove it after calling handle_function_call().
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   801
	 *
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   802
	 * However, if no further paramters are given, then il_operand_list will be NULL, and we will
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   803
	 * need to create a new object to hold the pointer to prev_il_instruction.
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   804
	 * This change will also be undone later in print_datatypes_error_c.
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   805
	 */
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   806
	if (NULL == symbol->il_operand_list)  symbol->il_operand_list = new il_operand_list_c;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   807
	if (NULL == symbol->il_operand_list)  ERROR;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   808
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   809
	((list_c *)symbol->il_operand_list)->insert_element(fake_prev_il_instruction, 0);
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   810
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   811
	generic_function_call_t fcall_param = {
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   812
		/* fcall_param.function_name               = */ symbol->function_name,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   813
		/* fcall_param.nonformal_operand_list      = */ symbol->il_operand_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   814
		/* fcall_param.formal_operand_list         = */ NULL,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   815
		/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_function,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   816
		/* fcall_param.candidate_functions         = */ symbol->candidate_functions,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   817
		/* fcall_param.called_function_declaration = */ symbol->called_function_declaration,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   818
		/* fcall_param.extensible_param_count      = */ symbol->extensible_param_count
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   819
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   820
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   821
/* TODO: check what error message (if any) the compiler will give out if this function invocation
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   822
 * is not preceded by a LD operator (or another equivalent operator or list of operators).
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   823
 */
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   824
	handle_function_invocation(symbol, fcall_param);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   825
	
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   826
	/* We now undo those changes to the abstract syntax tree made above! */
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   827
	((list_c *)symbol->il_operand_list)->remove_element(0);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   828
	if (((list_c *)symbol->il_operand_list)->n == 0) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   829
		/* if the list becomes empty, then that means that it did not exist before we made these changes, so we delete it! */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   830
		delete 	symbol->il_operand_list;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   831
		symbol->il_operand_list = NULL;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   832
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   833
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   834
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   835
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   836
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   837
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   838
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   839
// SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   840
void *print_datatypes_error_c::visit(il_expression_c *symbol) {
689
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   841
  /* Stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list if necessary. We can therefore ignore the 'il_operand' entry! */
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   842
  
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   843
  /* first give the parenthesised IL list a chance to print errors */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   844
  il_instruction_c *save_fake_prev_il_instruction = fake_prev_il_instruction;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   845
  symbol->simple_instr_list->accept(*this);
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   846
  fake_prev_il_instruction = save_fake_prev_il_instruction;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   847
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   848
  /* Now handle the operation (il_expr_operator) that will use the result coming from the parenthesised IL list (i.e. simple_instr_list) */
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   849
  il_operand = symbol->simple_instr_list; /* This is not a bug! The parenthesised expression will be used as the operator! */
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   850
  symbol->il_expr_operator->accept(*this);
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   851
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   852
return NULL;
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   853
}
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   854
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   855
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   856
/*   il_call_operator prev_declared_fb_name
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   857
 * | il_call_operator prev_declared_fb_name '(' ')'
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   858
 * | il_call_operator prev_declared_fb_name '(' eol_list ')'
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   859
 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   860
 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   861
 */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   862
/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   863
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   864
void *print_datatypes_error_c::visit(il_fb_call_c *symbol) {
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   865
	int extensible_param_count;                      /* unused vairable! Needed for compilation only! */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   866
	std::vector <symbol_c *> candidate_functions;    /* unused vairable! Needed for compilation only! */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   867
	generic_function_call_t fcall_param = {
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   868
		/* fcall_param.function_name               = */ symbol->fb_name,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   869
		/* fcall_param.nonformal_operand_list      = */ symbol->il_operand_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   870
		/* fcall_param.formal_operand_list         = */ symbol->il_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   871
		/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_FB,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   872
		/* fcall_param.candidate_functions         = */ candidate_functions,             /* will not be used, but must provide a reference to be able to compile */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   873
		/* fcall_param.called_function_declaration = */ symbol->called_fb_declaration,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   874
		/* fcall_param.extensible_param_count      = */ extensible_param_count           /* will not be used, but must provide a reference to be able to compile */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   875
	};
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   876
  
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   877
	handle_function_invocation(symbol, fcall_param);
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   878
	/* check the semantics of the CALC, CALCN operators! */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   879
	symbol->il_call_operator->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   880
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   881
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   882
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   883
/* | function_name '(' eol_list [il_param_list] ')' */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   884
/* NOTE: The parameter 'called_function_declaration' is used to pass data between the stage 3 and stage 4. */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   885
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; int extensible_param_count;)
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   886
void *print_datatypes_error_c::visit(il_formal_funct_call_c *symbol) {
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   887
	generic_function_call_t fcall_param = {
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   888
		/* fcall_param.function_name               = */ symbol->function_name,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   889
		/* fcall_param.nonformal_operand_list      = */ NULL,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   890
		/* fcall_param.formal_operand_list         = */ symbol->il_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   891
		/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_function,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   892
		/* fcall_param.candidate_functions         = */ symbol->candidate_functions,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   893
		/* fcall_param.called_function_declaration = */ symbol->called_function_declaration,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   894
		/* fcall_param.extensible_param_count      = */ symbol->extensible_param_count
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   895
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   896
  
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   897
	handle_function_invocation(symbol, fcall_param);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   898
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   899
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   900
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   901
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   902
//     void *visit(il_operand_list_c *symbol);
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   903
//     void *visit(simple_instr_list_c *symbol);
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   904
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   905
// SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   906
void *print_datatypes_error_c::visit(il_simple_instruction_c *symbol)	{
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   907
  if (symbol->prev_il_instruction.size() > 1) ERROR; /* There should be no labeled insructions inside an IL expression! */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   908
    
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   909
  il_instruction_c tmp_prev_il_instruction(NULL, NULL);
689
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   910
#if 0
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   911
  /* the print error algorithm will need access to the intersected candidate_datatype lists of all prev_il_instructions, as well as the 
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   912
   * list of the prev_il_instructions.
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   913
   * Instead of creating two 'global' (within the class) variables, we create a single il_instruction_c variable (fake_prev_il_instruction),
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   914
   * and shove that data into this single variable.
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   915
   */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   916
  if (symbol->prev_il_instruction.size() > 0)
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   917
    tmp_prev_il_instruction.candidate_datatypes = symbol->prev_il_instruction[0]->candidate_datatypes;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   918
  tmp_prev_il_instruction.prev_il_instruction = symbol->prev_il_instruction;
689
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   919
#endif
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   920
  
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   921
  /* the print error algorithm will need access to the intersected candidate_datatype lists of all prev_il_instructions, as well as the 
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   922
   * list of the prev_il_instructions.
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   923
   * Instead of creating two 'global' (within the class) variables, we create a single il_instruction_c variable (fake_prev_il_instruction),
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   924
   * and shove that data into this single variable.
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   925
   */
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   926
  tmp_prev_il_instruction.prev_il_instruction = symbol->prev_il_instruction;
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   927
  intersect_prev_candidate_datatype_lists(&tmp_prev_il_instruction);
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   928
  if (are_all_datatypes_equal(symbol->prev_il_instruction))
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   929
    if (symbol->prev_il_instruction.size() > 0)
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   930
      tmp_prev_il_instruction.datatype = (symbol->prev_il_instruction[0])->datatype;
45c35d829db9 Fix bug when handling IL expressions (i.e. IL instructions inside parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
   931
  
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   932
  
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   933
   /* copy the candidate_datatypes list */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   934
  fake_prev_il_instruction = &tmp_prev_il_instruction;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   935
  symbol->il_simple_instruction->accept(*this);
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   936
  fake_prev_il_instruction = NULL;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   937
  return NULL;
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   938
  
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   939
  
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   940
//   if (symbol->prev_il_instruction.size() == 0)  prev_il_instruction = NULL;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   941
//   else                                          prev_il_instruction = symbol->prev_il_instruction[0];
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   942
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   943
//   symbol->il_simple_instruction->accept(*this);
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   944
//   prev_il_instruction = NULL;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   945
//   return NULL;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   946
}
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   947
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   948
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   949
//     void *visit(il_param_list_c *symbol);
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   950
//     void *visit(il_param_assignment_c *symbol);
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   951
//     void *visit(il_param_out_assignment_c *symbol);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   952
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   953
/*******************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   954
/* B 2.2 Operators */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   955
/*******************/
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   956
void *print_datatypes_error_c::print_binary_operator_errors(const char *il_operator, symbol_c *symbol, bool deprecated_operation) {
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   957
	if (NULL == il_operand) {
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   958
		STAGE3_ERROR(0, symbol, symbol, "Missing operand for %s operator.", il_operator);		// message (a)
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   959
	} else if ((symbol->candidate_datatypes.size() == 0) && (il_operand->candidate_datatypes.size() > 0)) {
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   960
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '%s' operator.", il_operator);		// message (b)
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
   961
	} else if (NULL == symbol->datatype) {  // do NOT use !get_datatype_info_c::is_type_valid() here!
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   962
		STAGE3_WARNING(symbol, symbol, "Result of '%s' operation is never used.", il_operator);		// message (c)
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   963
	} else if (deprecated_operation)
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   964
		STAGE3_WARNING(symbol, symbol, "Deprecated operation for '%s' operator.", il_operator);		// message (d)
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   965
	return NULL;
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   966
}
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   967
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   968
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   969
void *print_datatypes_error_c::visit(  LD_operator_c *symbol) {return print_binary_operator_errors("LD"  , symbol);}  // I believe it will never emit messages (b) and (c)!!
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   970
void *print_datatypes_error_c::visit( LDN_operator_c *symbol) {return print_binary_operator_errors("LDN" , symbol);}  // I believe it will never emit message (c)
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   971
void *print_datatypes_error_c::visit(  ST_operator_c *symbol) {return print_binary_operator_errors("ST"  , symbol);}  // I believe it will never emit message (c)
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   972
void *print_datatypes_error_c::visit( STN_operator_c *symbol) {return print_binary_operator_errors("STN" , symbol);}  // I believe it will never emit message (c)
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   973
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   974
void *print_datatypes_error_c::visit(NOT_operator_c *symbol) {
470
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   975
	/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   976
	 *              NOT [<il_operand>]
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   977
	 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   978
	 *       We therefore consider it an error if an il_operand is specified!
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   979
	 */
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   980
	if (il_operand != NULL) {
470
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   981
		STAGE3_ERROR(0, symbol, symbol, "'NOT' operator may not have an operand.");
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   982
	} else if (symbol->candidate_datatypes.size() == 0)
470
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   983
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'NOT' operator.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   984
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   985
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   986
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   987
void *print_datatypes_error_c::visit(S_operator_c *symbol) {
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   988
	if (NULL != symbol->called_fb_declaration) /* FB call semantics */  return handle_implicit_il_fb_invocation("S", symbol, symbol->called_fb_declaration);
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   989
	else                                       /* Reset   semantics */  return print_binary_operator_errors    ("S", symbol);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   990
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   991
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   992
void *print_datatypes_error_c::visit(R_operator_c *symbol) {
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   993
	if (NULL != symbol->called_fb_declaration) /* FB call semantics */  return handle_implicit_il_fb_invocation("R", symbol, symbol->called_fb_declaration);
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 829
diff changeset
   994
	else                                       /* Reset   semantics */  return print_binary_operator_errors    ("R", symbol);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   995
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   996
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   997
void *print_datatypes_error_c::visit( S1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "S1", symbol, symbol->called_fb_declaration);}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   998
void *print_datatypes_error_c::visit( R1_operator_c *symbol) {return handle_implicit_il_fb_invocation( "R1", symbol, symbol->called_fb_declaration);}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   999
void *print_datatypes_error_c::visit(CLK_operator_c *symbol) {return handle_implicit_il_fb_invocation("CLK", symbol, symbol->called_fb_declaration);}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
  1000
void *print_datatypes_error_c::visit( CU_operator_c *symbol) {return handle_implicit_il_fb_invocation( "CU", symbol, symbol->called_fb_declaration);}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
  1001
void *print_datatypes_error_c::visit( CD_operator_c *symbol) {return handle_implicit_il_fb_invocation( "CD", symbol, symbol->called_fb_declaration);}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
  1002
void *print_datatypes_error_c::visit( PV_operator_c *symbol) {return handle_implicit_il_fb_invocation( "PV", symbol, symbol->called_fb_declaration);}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
  1003
void *print_datatypes_error_c::visit( IN_operator_c *symbol) {return handle_implicit_il_fb_invocation( "IN", symbol, symbol->called_fb_declaration);}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
  1004
void *print_datatypes_error_c::visit( PT_operator_c *symbol) {return handle_implicit_il_fb_invocation( "PT", symbol, symbol->called_fb_declaration);}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
  1005
483
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1006
void *print_datatypes_error_c::visit( AND_operator_c *symbol) {return print_binary_operator_errors("AND" , symbol);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1007
void *print_datatypes_error_c::visit(  OR_operator_c *symbol) {return print_binary_operator_errors( "OR" , symbol);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1008
void *print_datatypes_error_c::visit( XOR_operator_c *symbol) {return print_binary_operator_errors("XOR" , symbol);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1009
void *print_datatypes_error_c::visit(ANDN_operator_c *symbol) {return print_binary_operator_errors("ANDN", symbol);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1010
void *print_datatypes_error_c::visit( ORN_operator_c *symbol) {return print_binary_operator_errors( "ORN", symbol);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1011
void *print_datatypes_error_c::visit(XORN_operator_c *symbol) {return print_binary_operator_errors("XORN", symbol);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1012
void *print_datatypes_error_c::visit( ADD_operator_c *symbol) {return print_binary_operator_errors("ADD" , symbol, symbol->deprecated_operation);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1013
void *print_datatypes_error_c::visit( SUB_operator_c *symbol) {return print_binary_operator_errors("SUB" , symbol, symbol->deprecated_operation);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1014
void *print_datatypes_error_c::visit( MUL_operator_c *symbol) {return print_binary_operator_errors("MUL" , symbol, symbol->deprecated_operation);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1015
void *print_datatypes_error_c::visit( DIV_operator_c *symbol) {return print_binary_operator_errors("DIV" , symbol, symbol->deprecated_operation);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1016
void *print_datatypes_error_c::visit( MOD_operator_c *symbol) {return print_binary_operator_errors("MOD" , symbol);}
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1017
484
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1018
void *print_datatypes_error_c::visit(  GT_operator_c *symbol) {return print_binary_operator_errors( "GT" , symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1019
void *print_datatypes_error_c::visit(  GE_operator_c *symbol) {return print_binary_operator_errors( "GE" , symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1020
void *print_datatypes_error_c::visit(  EQ_operator_c *symbol) {return print_binary_operator_errors( "EQ" , symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1021
void *print_datatypes_error_c::visit(  LT_operator_c *symbol) {return print_binary_operator_errors( "LT" , symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1022
void *print_datatypes_error_c::visit(  LE_operator_c *symbol) {return print_binary_operator_errors( "LE" , symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1023
void *print_datatypes_error_c::visit(  NE_operator_c *symbol) {return print_binary_operator_errors( "NE" , symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1024
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1025
  
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1026
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1027
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1028
void *print_datatypes_error_c::handle_conditional_flow_control_IL_instruction(symbol_c *symbol, const char *oper) {
841
aed36f08545d Fix detection of datatype errors on IL conditional flow control operators (JMPC, RETC, ...)
mjsousa
parents: 834
diff changeset
  1029
	if (!get_datatype_info_c::is_type_valid(symbol->datatype))
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1030
		STAGE3_ERROR(0, symbol, symbol, "%s operator must be preceded by an IL instruction producing a BOOL value.", oper);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1031
	return NULL;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1032
}
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1033
487
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1034
void *print_datatypes_error_c::visit(  CAL_operator_c *symbol) {return NULL;}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1035
void *print_datatypes_error_c::visit( CALC_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "CALC" );}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1036
void *print_datatypes_error_c::visit(CALCN_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "CALCN");}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1037
void *print_datatypes_error_c::visit(  RET_operator_c *symbol) {return NULL;}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1038
void *print_datatypes_error_c::visit( RETC_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "RETC" );}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1039
void *print_datatypes_error_c::visit(RETCN_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "RETCN");}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1040
void *print_datatypes_error_c::visit(  JMP_operator_c *symbol) {return NULL;}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1041
void *print_datatypes_error_c::visit( JMPC_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "JMPC" );}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1042
void *print_datatypes_error_c::visit(JMPCN_operator_c *symbol) {return handle_conditional_flow_control_IL_instruction(symbol, "JMPCN");}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1043
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1044
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1045
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1046
/* Symbol class handled together with function call checks */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1047
// void *visit(il_assign_operator_c *symbol, variable_name);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1048
/* Symbol class handled together with function call checks */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1049
// void *visit(il_assign_operator_c *symbol, option, variable_name);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1050
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1051
/***************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1052
/* B.3 - Language ST (Structured Text) */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1053
/***************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1054
/***********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1055
/* B 3.1 - Expressions */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1056
/***********************/
936
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1057
/* SYM_REF1(deref_operator_c, exp)  --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1058
void *print_datatypes_error_c::visit(deref_operator_c  *symbol) {
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1059
	symbol->exp->accept(*this);
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1060
	/* we should really check whether the expression is merely a variable. For now, leave it for the future! */
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1061
	if ((symbol->candidate_datatypes.size() == 0) && (symbol->exp->candidate_datatypes.size() > 0))
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1062
		STAGE3_ERROR(0, symbol, symbol, "^ operator must be preceded by a value of type REF_TO.");
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1063
	return NULL;
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1064
}
0f7bcc160568 Fix bug: Add support for de-referencing pointers to struct (struct_ptr^.elem1) when used inside FB.
mjsousa
parents: 933
diff changeset
  1065
933
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1066
/* SYM_REF1(deref_expression_c, exp)  --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1067
void *print_datatypes_error_c::visit(deref_expression_c  *symbol) {
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1068
	symbol->exp->accept(*this);
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1069
	/* we should really check whether the expression is merely a variable. For now, leave it for the future! */
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1070
	if ((symbol->candidate_datatypes.size() == 0) && (symbol->exp->candidate_datatypes.size() > 0))
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1071
		STAGE3_ERROR(0, symbol, symbol, "DREF operator must be used with a value of type REF_TO.");
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1072
	return NULL;
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1073
}
76324f461aed Add support for de-referencing of REF_TO datatypes (Note: dereferencing of arrays and structs not yet supported!)
mjsousa
parents: 895
diff changeset
  1074
873
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1075
/* SYM_REF1(ref_expression_c, exp)  --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1076
void *print_datatypes_error_c::visit(  ref_expression_c  *symbol) {
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1077
	symbol->exp->accept(*this);
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1078
	/* we should really check whether the expression is merely a variable. For now, leave it for the future! */
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1079
	if ((symbol->candidate_datatypes.size() == 0) && (symbol->exp->candidate_datatypes.size() > 0))
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1080
		STAGE3_ERROR(0, symbol, symbol, "REF operator must be used with a variable.");
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1081
	return NULL;
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1082
}
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 848
diff changeset
  1083
    
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1084
485
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1085
void *print_datatypes_error_c::print_binary_expression_errors(const char *operation, symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr, bool deprecated_operation) {
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1086
	l_expr->accept(*this);
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1087
	r_expr->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1088
	if ((symbol->candidate_datatypes.size() == 0) 		&&
485
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1089
		(l_expr->candidate_datatypes.size() > 0)	&&
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1090
		(r_expr->candidate_datatypes.size() > 0))
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1091
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '%s' expression.", operation);
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1092
        if (deprecated_operation)
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1093
                STAGE3_WARNING(symbol, symbol, "Deprecated operation for '%s' expression.", operation);
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1094
	return NULL;
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1095
}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1096
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1097
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1098
void *print_datatypes_error_c::visit(    or_expression_c *symbol) {return print_binary_expression_errors( "OR", symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1099
void *print_datatypes_error_c::visit(   xor_expression_c *symbol) {return print_binary_expression_errors("XOR", symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1100
void *print_datatypes_error_c::visit(   and_expression_c *symbol) {return print_binary_expression_errors("AND", symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1101
void *print_datatypes_error_c::visit(   equ_expression_c *symbol) {return print_binary_expression_errors( "=" , symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1102
void *print_datatypes_error_c::visit(notequ_expression_c *symbol) {return print_binary_expression_errors( "<>", symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1103
void *print_datatypes_error_c::visit(    lt_expression_c *symbol) {return print_binary_expression_errors( "<" , symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1104
void *print_datatypes_error_c::visit(    gt_expression_c *symbol) {return print_binary_expression_errors( ">" , symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1105
void *print_datatypes_error_c::visit(    le_expression_c *symbol) {return print_binary_expression_errors( "<=", symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1106
void *print_datatypes_error_c::visit(    ge_expression_c *symbol) {return print_binary_expression_errors( ">=", symbol, symbol->l_exp, symbol->r_exp);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1107
void *print_datatypes_error_c::visit(   add_expression_c *symbol) {return print_binary_expression_errors( "+" , symbol, symbol->l_exp, symbol->r_exp, symbol->deprecated_operation);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1108
void *print_datatypes_error_c::visit(   sub_expression_c *symbol) {return print_binary_expression_errors( "-" , symbol, symbol->l_exp, symbol->r_exp, symbol->deprecated_operation);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1109
void *print_datatypes_error_c::visit(   mul_expression_c *symbol) {return print_binary_expression_errors( "*" , symbol, symbol->l_exp, symbol->r_exp, symbol->deprecated_operation);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1110
void *print_datatypes_error_c::visit(   div_expression_c *symbol) {return print_binary_expression_errors( "/" , symbol, symbol->l_exp, symbol->r_exp, symbol->deprecated_operation);}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1111
void *print_datatypes_error_c::visit(   mod_expression_c *symbol) {return print_binary_expression_errors("MOD", symbol, symbol->l_exp, symbol->r_exp);}
490
29f6ab0bf954 Add EXPT widen table.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
  1112
void *print_datatypes_error_c::visit( power_expression_c *symbol) {return print_binary_expression_errors( "**", symbol, symbol->l_exp, symbol->r_exp);}
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1113
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1114
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1115
void *print_datatypes_error_c::visit(neg_expression_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1116
	symbol->exp->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1117
	if ((symbol->candidate_datatypes.size() == 0)      &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1118
		(symbol->exp->candidate_datatypes.size() > 0))
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
  1119
		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'NEG' expression.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1120
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1121
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1122
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1123
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1124
void *print_datatypes_error_c::visit(not_expression_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1125
	symbol->exp->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1126
	if ((symbol->candidate_datatypes.size() == 0)      &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1127
		(symbol->exp->candidate_datatypes.size() > 0))
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
  1128
		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'NOT' expression.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1129
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1130
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1131
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1132
/* NOTE: The parameter 'called_function_declaration', 'extensible_param_count' and 'candidate_functions' are used to pass data between the stage 3 and stage 4. */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1133
/*    formal_param_list -> may be NULL ! */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1134
/* nonformal_param_list -> may be NULL ! */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1135
// SYM_REF3(function_invocation_c, function_name, formal_param_list, nonformal_param_list, symbol_c *called_function_declaration; int extensible_param_count; std::vector <symbol_c *> candidate_functions;)
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1136
void *print_datatypes_error_c::visit(function_invocation_c *symbol) {
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1137
	generic_function_call_t fcall_param = {
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1138
		/* fcall_param.function_name               = */ symbol->function_name,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1139
		/* fcall_param.nonformal_operand_list      = */ symbol->nonformal_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1140
		/* fcall_param.formal_operand_list         = */ symbol->formal_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1141
		/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_function,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1142
		/* fcall_param.candidate_functions         = */ symbol->candidate_functions,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1143
		/* fcall_param.called_function_declaration = */ symbol->called_function_declaration,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1144
		/* fcall_param.extensible_param_count      = */ symbol->extensible_param_count
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1145
	};
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1146
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1147
	handle_function_invocation(symbol, fcall_param);
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1148
	return NULL;
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1149
}
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1150
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1151
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1152
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1153
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1154
/* B 3.2 Statements */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1155
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1156
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1157
/*********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1158
/* B 3.2.1 Assignment Statements */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1159
/*********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1160
void *print_datatypes_error_c::visit(assignment_statement_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1161
	symbol->l_exp->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1162
	symbol->r_exp->accept(*this);
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1163
	if ((!get_datatype_info_c::is_type_valid(symbol->l_exp->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1164
	    (!get_datatype_info_c::is_type_valid(symbol->r_exp->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1165
	    (symbol->l_exp->candidate_datatypes.size() > 0)	&&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1166
	    (symbol->r_exp->candidate_datatypes.size() > 0))
491
6f4083fe169e Edit error message.
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
  1167
		STAGE3_ERROR(0, symbol, symbol, "Incompatible data types for ':=' operation.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1168
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1169
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1170
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1171
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1172
/*****************************************/
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1173
/* B 3.2.2 Subprogram Control Statements */
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1174
/*****************************************/
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1175
/* fb_name '(' [param_assignment_list] ')' */
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1176
/*    formal_param_list -> may be NULL ! */
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1177
/* nonformal_param_list -> may be NULL ! */
439
cf7d6862033d Add semantic verification of FB calls in IL (not yet complete - missing printing of errors!)
Mario de Sousa <msousa@fe.up.pt>
parents: 438
diff changeset
  1178
/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1179
// SYM_REF3(fb_invocation_c, fb_name, formal_param_list, nonformal_param_list, symbol_c *called_fb_declaration;)
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1180
void *print_datatypes_error_c::visit(fb_invocation_c *symbol) {
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1181
	int extensible_param_count;                      /* unused vairable! Needed for compilation only! */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1182
	std::vector <symbol_c *> candidate_functions;    /* unused vairable! Needed for compilation only! */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1183
	generic_function_call_t fcall_param = {
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1184
		/* fcall_param.function_name               = */ symbol->fb_name,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1185
		/* fcall_param.nonformal_operand_list      = */ symbol->nonformal_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1186
		/* fcall_param.formal_operand_list         = */ symbol->formal_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1187
		/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_FB,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1188
		/* fcall_param.candidate_functions         = */ candidate_functions,             /* will not be used, but must provide a reference to be able to compile */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1189
		/* fcall_param.called_function_declaration = */ symbol->called_fb_declaration,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1190
		/* fcall_param.extensible_param_count      = */ extensible_param_count           /* will not be used, but must provide a reference to be able to compile */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1191
	};
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1192
	
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1193
	handle_function_invocation(symbol, fcall_param);
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1194
	return NULL;
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1195
}
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1196
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1197
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1198
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1199
/* B 3.2.3 Selection Statements */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1200
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1201
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1202
void *print_datatypes_error_c::visit(if_statement_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1203
	symbol->expression->accept(*this);
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1204
	if ((!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1205
	    (symbol->expression->candidate_datatypes.size() > 0)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1206
		STAGE3_ERROR(0, symbol->expression, symbol->expression, "Invalid data type for 'IF' condition (should be BOOL).");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1207
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1208
	if (NULL != symbol->statement_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1209
		symbol->statement_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1210
	if (NULL != symbol->elseif_statement_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1211
		symbol->elseif_statement_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1212
	if (NULL != symbol->else_statement_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1213
		symbol->else_statement_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1214
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1215
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1216
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1217
void *print_datatypes_error_c::visit(elseif_statement_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1218
	symbol->expression->accept(*this);
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1219
	if ((!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1220
	    (symbol->expression->candidate_datatypes.size() > 0)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1221
		STAGE3_ERROR(0, symbol->expression, symbol->expression, "Invalid data type for 'ELSIF' condition (should be BOOL).");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1222
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1223
	if (NULL != symbol->statement_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1224
		symbol->statement_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1225
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1226
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1227
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1228
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1229
void *print_datatypes_error_c::visit(case_statement_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1230
	symbol->expression->accept(*this);
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1231
	if ((!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1232
	    (symbol->expression->candidate_datatypes.size() > 0)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1233
		STAGE3_ERROR(0, symbol->expression, symbol->expression, "'CASE' quantity not an integer or enumerated.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1234
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1235
	symbol->case_element_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1236
	if (NULL != symbol->statement_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1237
		symbol->statement_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1238
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1239
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1240
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1241
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1242
/* B 3.2.4 Iteration Statements */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1243
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1244
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1245
void *print_datatypes_error_c::visit(for_statement_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1246
	symbol->control_variable->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1247
	symbol->beg_expression->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1248
	symbol->end_expression->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1249
	/* Control variable */
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1250
	if ((!get_datatype_info_c::is_type_valid(symbol->control_variable->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1251
	    (symbol->control_variable->candidate_datatypes.size() > 0)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1252
		STAGE3_ERROR(0, symbol->control_variable, symbol->control_variable, "Invalid data type for 'FOR' control variable.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1253
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1254
	/* BEG expression */
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1255
	if ((!get_datatype_info_c::is_type_valid(symbol->beg_expression->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1256
	    (symbol->beg_expression->candidate_datatypes.size() > 0)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1257
		STAGE3_ERROR(0, symbol->beg_expression, symbol->beg_expression, "Invalid data type for 'FOR' begin expression.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1258
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1259
	/* END expression */
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1260
	if ((!get_datatype_info_c::is_type_valid(symbol->end_expression->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1261
	    (symbol->end_expression->candidate_datatypes.size() > 0)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1262
		STAGE3_ERROR(0, symbol->end_expression, symbol->end_expression, "Invalid data type for 'FOR' end expression.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1263
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1264
	/* BY expression */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1265
	if ((NULL != symbol->by_expression) &&
848
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1266
	    (!get_datatype_info_c::is_type_valid(symbol->by_expression->datatype)) &&
db78824cec23 Use get_datatype_info_c::is_type_valid() to determine datatype validity
mjsousa
parents: 847
diff changeset
  1267
	    (symbol->end_expression->candidate_datatypes.size() > 0)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1268
		STAGE3_ERROR(0, symbol->by_expression, symbol->by_expression, "Invalid data type for 'FOR' by expression.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1269
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1270
	/* DO statement */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1271
	if (NULL != symbol->statement_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1272
		symbol->statement_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1273
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1274
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1275
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1276
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1277
void *print_datatypes_error_c::visit(while_statement_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1278
	symbol->expression->accept(*this);
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
  1279
	if (!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1280
		STAGE3_ERROR(0, symbol->expression, symbol->expression, "Invalid data type for 'WHILE' condition.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1281
		return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1282
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1283
	if (NULL != symbol->statement_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1284
		symbol->statement_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1285
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1286
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1287
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1288
void *print_datatypes_error_c::visit(repeat_statement_c *symbol) {
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 558
diff changeset
  1289
	if (!get_datatype_info_c::is_type_valid(symbol->expression->datatype)) {
995
ce997a27c516 Better identification of error location in some error messages.
mjsousa
parents: 958
diff changeset
  1290
		STAGE3_ERROR(0, symbol->expression, symbol->expression, "Invalid data type for 'REPEAT' condition.");
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1291
		return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1292
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1293
	if (NULL != symbol->statement_list)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1294
		symbol->statement_list->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1295
	symbol->expression->accept(*this);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1296
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1297
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1298
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1299
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1300
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1301
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1302