stage3/print_datatypes_error.cc
author Mario de Sousa <msousa@fe.up.pt>
Thu, 04 Oct 2012 18:54:15 +0100
changeset 671 d28c7ebaca21
parent 558 9273dfc5fa7c
child 676 ca4f17211251
permissions -rwxr-xr-x
Remove deprecated search_expression_type_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
     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
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   106
/* Verify if the datatypes of all prev_il_instructions are valid and equal!  */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   107
static bool are_all_datatypes_of_prev_il_instructions_datatypes_equal(il_instruction_c *symbol) {
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   108
	if (NULL == symbol) ERROR;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   109
	bool res;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   110
	
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   111
	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
   112
		res = is_type_valid(symbol->prev_il_instruction[0]->datatype);
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   113
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   114
	for (unsigned int i = 1; i < symbol->prev_il_instruction.size(); i++)
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   115
		res &= is_type_equal(symbol->prev_il_instruction[i-1]->datatype, symbol->prev_il_instruction[i]->datatype);
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
	return res;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   118
}
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   119
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   120
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   121
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   122
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
   123
/* a helper function... */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   124
symbol_c *print_datatypes_error_c::base_type(symbol_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
   125
	/* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   126
	 *       in the code.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   127
	 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   128
	if (symbol == NULL) 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
   129
	return (symbol_c *)symbol->accept(search_base_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
   130
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   131
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   132
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   133
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   134
/*
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   135
typedef struct {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   136
  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
   137
  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
   138
  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
   139
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   140
  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
   141
  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
   142
  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
   143
} 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
   144
*/
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   145
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
   146
	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
   147
	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
   148
	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
   149
	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
   150
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   151
	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
   152
	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
   153
	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
   154
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   155
	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
   156
		ERROR;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   157
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   158
	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
   159
	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
   160
		/* 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
   161
		/* 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
   162
		ERROR;
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   163
	}
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   164
	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
   165
		/* 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
   166
		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
   167
		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
   168
		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
   169
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   170
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   171
	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
   172
		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
   173
		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
   174
			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
   175
			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
   176
				param_value = fcp_iterator.get_current_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
   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 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
   179
				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
   180
					function_invocation_error = true;
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   181
					STAGE3_ERROR(0, param_name, param_name, "Duplicate parameter '%s' when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   182
					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
   183
				}
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   184
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   185
				/* 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
   186
				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
   187
					function_invocation_error = true;
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   188
					STAGE3_ERROR(0, param_name, param_name, "Invalid parameter '%s' when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   189
					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
   190
				} 
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   191
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   192
				/* 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
   193
				/* 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
   194
				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
   195
				/* 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
   196
				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
   197
				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
   198
					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
   199
					    (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
   200
						function_invocation_error = true;
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   201
						STAGE3_ERROR(0, param_name, param_name, "Invalid assignment syntax ':=' used for parameter '%s', when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   202
						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
   203
					}
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   204
				} 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
   205
					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
   206
						function_invocation_error = true;
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   207
						STAGE3_ERROR(0, param_name, param_name, "Invalid assignment syntax '=>' used for parameter '%s', when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_c *)fcall_data.function_name)->value);
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   208
						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
   209
					}
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   210
				} 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
   211
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   212
				if (NULL == 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
   213
					function_invocation_error = true;
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   214
					STAGE3_ERROR(0, param_value, param_value, "Data type incompatibility between parameter '%s' and value being passed, when invoking %s '%s'", ((identifier_c *)param_name)->value, POU_str, ((identifier_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
   215
					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
   216
				}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   217
			}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   218
		}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   219
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   220
	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
   221
		fcall_data.nonformal_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
   222
		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
   223
			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
   224
		  		/* 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
   225
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   226
				/* 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
   227
				 * 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
   228
				 * 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
   229
				 * However, 
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   230
				 *     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
   231
				 *     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
   232
				 * 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
   233
				 */
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   234
				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
   235
				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
   236
					/* 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
   237
					/* 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
   238
					 * 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
   239
					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
   240
						function_invocation_error = true;
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   241
						STAGE3_ERROR(0, fcall, fcall, "No available data to pass to first parameter of IL function %s. Missing a previous LD instruction?", ((identifier_c *)fcall_data.function_name)->value);
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
#if 0
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   244
					/* 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
   245
					 * 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
   246
					 * 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
   247
					 * 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
   248
					 * 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
   249
					 * 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
   250
					 */
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   251
					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
   252
						symbol_c *value = il_instruction_symbol->prev_il_instruction[p];  
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   253
						if (!is_type_valid(value->datatype)) {
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   254
							function_invocation_error = true;
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   255
							STAGE3_ERROR(0, fcall, fcall, "Data type incompatibility for value passed to first parameter when invoking function '%s'", ((identifier_c *)fcall_data.function_name)->value);
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   256
							STAGE3_ERROR(0, value, value, "This is the IL instruction producing the incompatible data type to first parameter of function '%s'", ((identifier_c *)fcall_data.function_name)->value);
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   257
						}
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   258
					}
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   259
#else
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   260
					if (!is_type_valid(il_instruction_symbol->datatype)) {
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   261
						function_invocation_error = true;
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   262
						STAGE3_ERROR(0, fcall, fcall, "Data type incompatibility between value in IL 'accumulator' and first parameter of function '%s'", ((identifier_c *)fcall_data.function_name)->value);
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   263
					}
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   264
#endif
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   265
					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
   266
						/* 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
   267
						return;
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   268
				}
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   269
				else if (!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
   270
					function_invocation_error = true;
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   271
					STAGE3_ERROR(0, param_value, param_value, "Data type incompatibility for value passed in position %d when invoking %s '%s'", i, POU_str, ((identifier_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
   272
				}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   273
			}
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
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   276
	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
   277
		function_invocation_error = true;
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   278
		STAGE3_ERROR(0, fcall, fcall, "Unable to resolve which overloaded %s '%s' is being invoked.", POU_str, ((identifier_c *)fcall_data.function_name)->value);
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   279
	}
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   280
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   281
	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
   282
		/* No compatible function exists */
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   283
		STAGE3_ERROR(2, fcall, fcall, "Invalid parameters when invoking %s '%s'", POU_str, ((identifier_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
   284
	} 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   285
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   286
	return;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   287
}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
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
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   290
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   291
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
   292
	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
   293
		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
   294
		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
   295
	}
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   296
	il_operand->accept(*this);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   297
	
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
   298
	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
   299
		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
   300
		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
   301
	}
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   302
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   303
	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
   304
		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
   305
		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
   306
	}
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   307
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
   308
	/* 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
   309
	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
   310
	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
   311
		/* 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
   312
		/* 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
   313
		*        (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
   314
		*        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
   315
		*        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
   316
		*        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
   317
		*/
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
   318
		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
   319
		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
   320
	}
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   321
	if (!are_all_datatypes_of_prev_il_instructions_datatypes_equal(fake_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
   322
		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
   323
		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
   324
	}
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   325
	
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   326
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   327
	/* 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
   328
	 *       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
   329
	 *       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
   330
	 *       be printed out!
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   331
	 */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   332
	if (NULL == il_operand->datatype) {
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   333
		/* 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
   334
// 		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
   335
			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
   336
			return NULL;
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   337
// 		}
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   338
	}
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   339
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   340
	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
   341
}
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   342
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   343
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
   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
/* 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
   346
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   348
/* 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
   349
/******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   350
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
   351
	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
   352
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   353
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   354
		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
   355
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   357
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   358
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   359
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
   360
	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
   361
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   362
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   363
		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
   364
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   366
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   367
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   368
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
   369
	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
   370
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_REAL data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   371
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   372
		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
   373
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   375
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   376
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   377
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
   378
	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
   379
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   380
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   381
		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
   382
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   384
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   385
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   386
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
   387
	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
   388
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   389
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   390
		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
   391
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   393
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   394
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   395
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
   396
	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
   397
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   398
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   399
		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
   400
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   402
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   403
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   404
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
   405
	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
   406
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for ANY_INT data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   407
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   408
		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
   409
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   411
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   412
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   413
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
   414
	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
   415
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type));
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   416
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   417
		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
   418
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   420
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   421
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   422
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
   423
	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
   424
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type));
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   425
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   426
		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
   427
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   429
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   430
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   431
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
   432
	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
   433
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for %s data type.", elementary_type_c::to_string(symbol->type));
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   434
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   435
		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
   436
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   438
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   439
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   440
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
   441
	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
   442
		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for %s data type.", elementary_type_c::to_string(symbol->type));
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   443
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   444
		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
   445
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   447
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   448
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   449
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
   450
	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
   451
		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   452
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   453
		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
   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
	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
   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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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
   459
	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
   460
		STAGE3_ERROR(0, symbol, symbol, "Value is not valid for ANY_BOOL data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   461
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   462
		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
   463
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/*******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   468
/* 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
   469
/*******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   470
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
   471
	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
   472
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for WSTRING data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   473
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   474
		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
   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
	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
   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
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
   480
	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
   481
		STAGE3_ERROR(0, symbol, symbol, "Numerical value exceeds range for STRING data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   482
	} else if (NULL == symbol->datatype) {
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(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
   484
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   485
	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
   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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   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
/************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   493
/************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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
   495
	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
   496
		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TIME data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   497
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   498
		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
   499
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   504
/* 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
   505
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   506
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
   507
	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
   508
		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for TOD data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   509
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   510
		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
   511
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   513
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   514
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   515
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
   516
	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
   517
		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DATE data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   518
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   519
		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
   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
	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
   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
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
   525
	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
   526
		STAGE3_ERROR(0, symbol, symbol, "Invalid syntax for DT data type.");
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   527
	} else if (NULL == symbol->datatype) {
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   528
		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
   529
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   530
	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
   531
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   532
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   533
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   534
/* 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
   535
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   536
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   537
/* 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
   538
/********************************/
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   539
void *print_datatypes_error_c::visit(simple_spec_init_c *symbol) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   540
	if (!is_type_valid(symbol->simple_specification->datatype)) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   541
		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
   542
	} else if (NULL != symbol->constant) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   543
		if (!is_type_valid(symbol->constant->datatype))
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   544
			STAGE3_ERROR(0, symbol->constant, symbol->constant, "Initial value has incompatible data type.");
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   545
	} else if (!is_type_valid(symbol->datatype)) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   546
		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
   547
		        * 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
   548
			*/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   549
	}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   550
	return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   551
}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   552
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
   553
void *print_datatypes_error_c::visit(data_type_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
   554
	// 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
   555
	/* 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
   556
	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
   557
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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
   560
	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
   561
		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
   562
	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
   563
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   568
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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
   570
	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
   571
		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
   572
	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
   573
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   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
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
   579
	if (symbol->candidate_datatypes.size() == 0) ERROR;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   580
	if (!is_type_valid(symbol->datatype))
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   581
		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
   582
	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
   583
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   584
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   585
/*************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   586
/* 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
   587
/*************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   588
/*  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
   589
// 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
   590
void *print_datatypes_error_c::visit(array_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
   591
	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
   592
		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
   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
	/* 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
   595
	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
   596
	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
   597
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   598
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   599
/* 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
   600
// SYM_LIST(subscript_list_c)
549
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   601
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
   602
	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
   603
		int start_error_count = error_count;
322f063daa9f Fix the previous commit: check for errors in expressions used as subscripts.
mjsousa <msousa@fe.up.pt>
parents: 549
diff changeset
   604
		symbol->elements[i]->accept(*this);
551
a75e3aea98ff Fix comment.
mjsousa <msousa@fe.up.pt>
parents: 550
diff changeset
   605
		/* The following error message will only get printed if the current_display_error_level is set higher than 0! */
550
322f063daa9f Fix the previous commit: check for errors in expressions used as subscripts.
mjsousa <msousa@fe.up.pt>
parents: 549
diff changeset
   606
		if ((start_error_count == error_count) && (NULL == symbol->elements[i]->datatype))
549
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   607
			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
   608
	}
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   609
	return NULL;
af9517cad953 Fix data type check array subscript field.
Manuele Conti <conti.ma@alice.it>
parents: 514
diff changeset
   610
}
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
   611
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/*  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
   614
/*  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
   615
 *           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
   616
 *           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
   617
 *           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
   618
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   619
// 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
   620
/* NOTE: We do not recursively determine the data types of each field_selector in fill_candidate_datatypes_c,
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
 * so it does not make sense to recursively visit all the field_selectors to print out error messages. 
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   622
 * Maybe in the future, if we find the need to print out more detailed error messages, we might do it that way. For now, we don't!
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *print_datatypes_error_c::visit(structured_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
   625
	if (symbol->candidate_datatypes.size() == 0)
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
   626
		STAGE3_ERROR(0, symbol, symbol, "Undeclared structured/FB 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
   627
	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
   628
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   629
502
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
/******************************************/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   633
/* 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
   634
/******************************************/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   635
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   636
/*  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
   637
// 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
   638
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
   639
	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
   640
	return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   641
}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   642
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   643
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   644
/*  [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
   645
/* 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
   646
// 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
   647
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
   648
  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
   649
  /* 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
   650
  // symbol->location->accept(*this); 
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   651
  if ((is_type_valid(symbol->located_var_spec_init->datatype)) && (!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
   652
    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
   653
  return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   654
}  
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   655
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   656
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
   657
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   659
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   661
/* 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
   662
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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
   664
	search_varfb_instance_type = new search_varfb_instance_type_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
   665
	/* We do not check for data type errors in variable declarations, Skip this for now... */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
// 	symbol->var_declarations_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
   667
	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
   668
	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
   669
	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
   670
	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
   671
	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
   672
	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
   673
	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
   674
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   676
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   678
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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
   680
	search_varfb_instance_type = new search_varfb_instance_type_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
   681
	/* We do not check for data type errors in variable declarations, Skip this for now... */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
// 	symbol->var_declarations->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
   683
	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
   684
	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
   685
	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
   686
	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
   687
	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
   688
	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
   689
	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
   690
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   691
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   694
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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
   696
	search_varfb_instance_type = new search_varfb_instance_type_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
   697
	/* We do not check for data type errors in variable declarations, Skip this for now... */
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 492
diff changeset
   698
	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
   699
	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
   700
	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
   701
	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
   702
	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
   703
	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
   704
	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
   705
	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
   706
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   707
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   708
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   709
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   710
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   711
/* 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
   712
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   713
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
   714
	// 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
   715
	/* 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
   716
	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
   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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   721
/****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   724
/***********************************/
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   725
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
   726
// 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
   727
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   728
/* | 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
   729
// 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
   730
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
   731
	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
   732
		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
   733
#if 0
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   734
		/* 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
   735
		 * 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
   736
		 */
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
   737
		/* 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
   738
		 * 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
   739
		 */
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
   740
		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
   741
			/* 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
   742
			/* 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
   743
			 * 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
   744
			 * 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
   745
			 * 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
   746
			 * 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
   747
			 */
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
			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
   749
			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
   750
			*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
   751
			/* 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
   752
			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
   753
			/* 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
   754
			 * 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
   755
			 */
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
		}
492
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   757
#endif
6ae697b34f2d Print correct error message when handling IL function calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 491
diff changeset
   758
		/* 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
   759
		 * 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
   760
		 * 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
   761
		 * 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
   762
		 */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   763
		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
   764
		intersect_prev_candidate_datatype_lists(&tmp_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
   765
		if (are_all_datatypes_of_prev_il_instructions_datatypes_equal(symbol))
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   766
			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
   767
				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
   768
		
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   769
		/* 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
   770
		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
   771
		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
   772
		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
   773
	}
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   774
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   775
	return NULL;
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   776
}
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   777
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
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
   780
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
   781
	il_operand = symbol->il_operand;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   782
	if (NULL != symbol->il_operand) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   783
		symbol->il_operand->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
   784
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	/* recursive call to see whether data types are compatible */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   787
	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
   788
	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
   789
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   791
/* | 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
   792
/* 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
   793
// 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
   794
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
   795
	/* 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
   796
	 * 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
   797
	 * 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
   798
	 *
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   799
	 * 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
   800
	 * 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
   801
	 * 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
   802
	 */
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   803
	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
   804
	if (NULL == symbol->il_operand_list)  ERROR;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   805
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   806
	((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
   807
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   808
	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
   809
		/* 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
   810
		/* 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
   811
		/* 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
   812
		/* 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
   813
		/* 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
   814
		/* 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
   815
		/* 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
   816
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   817
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
   818
/* 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
   819
 * 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
   820
 */
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   821
	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
   822
	
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   823
	/* 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
   824
	((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
   825
	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
   826
		/* 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
   827
		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
   828
		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
   829
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   830
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
   831
	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
   832
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   833
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   834
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   835
/* | 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
   836
// 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
   837
void *print_datatypes_error_c::visit(il_expression_c *symbol) {
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   838
  /* 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
   839
  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
   840
  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
   841
  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
   842
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   843
  /* 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
   844
  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
   845
  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
   846
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   847
return NULL;
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   848
}
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   849
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
   850
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   851
/*   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
   852
 * | 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
   853
 * | 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
   854
 * | 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
   855
 * | 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
   856
 */
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   857
/* 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
   858
// 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
   859
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
   860
	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
   861
	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
   862
	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
   863
		/* 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
   864
		/* 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
   865
		/* 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
   866
		/* 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
   867
		/* 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
   868
		/* 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
   869
		/* 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
   870
	};
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   871
  
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   872
	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
   873
	/* 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
   874
	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
   875
	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
   876
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   877
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   878
/* | 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
   879
/* 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
   880
// 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
   881
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
   882
	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
   883
		/* 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
   884
		/* 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
   885
		/* 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
   886
		/* 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
   887
		/* 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
   888
		/* 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
   889
		/* 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
   890
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   891
  
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 434
diff changeset
   892
	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
   893
	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
   894
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   895
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   896
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   897
//     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
   898
//     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
   899
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   900
// 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
   901
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
   902
  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
   903
    
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   904
  il_instruction_c tmp_prev_il_instruction(NULL, NULL);
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   905
  /* 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
   906
   * 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
   907
   * 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
   908
   * 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
   909
   */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   910
  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
   911
    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
   912
  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
   913
  
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   914
   /* 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
   915
  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
   916
  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
   917
  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
   918
  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
   919
  
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   920
  
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   921
//   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
   922
//   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
   923
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 458
diff changeset
   924
//   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
   925
//   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
   926
//   return NULL;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   927
}
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   928
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
   929
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   930
//     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
   931
//     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
   932
//     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
   933
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   934
/*******************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   935
/* 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
   936
/*******************/
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   937
void *print_datatypes_error_c::print_binary_operator_errors(const char *il_operator, symbol_c *symbol, bool deprecated_operation) {
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   938
	if ((symbol->candidate_datatypes.size() == 0) && (il_operand->candidate_datatypes.size() > 0)) {
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   939
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for '%s' operator.", il_operator);
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   940
	} else if (NULL == symbol->datatype) {
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   941
		STAGE3_WARNING(symbol, symbol, "Result of '%s' operation is never used.", il_operator);
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   942
	} else if (deprecated_operation)
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   943
		STAGE3_WARNING(symbol, symbol, "Deprecated operation for '%s' operator.", il_operator);
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   944
	return NULL;
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   945
}
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   946
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   947
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
   948
void *print_datatypes_error_c::visit(LD_operator_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
   949
	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
   950
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   951
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *print_datatypes_error_c::visit(LDN_operator_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
   953
	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
   954
		(il_operand->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
   955
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'LDN' 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
   956
	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
   957
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   958
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   959
void *print_datatypes_error_c::visit(ST_operator_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
   960
	/* MANU:
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   961
	 * if prev_instruction is NULL we can print a message error or warning error like:
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   962
	 * we can't use a ST like first instruction.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   963
	 * What do you think?
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   964
	 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   965
	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
   966
		(il_operand->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
   967
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'ST' 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
   968
	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
   969
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   970
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   971
void *print_datatypes_error_c::visit(STN_operator_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
   972
	/* MANU:
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	 * if prev_instruction is NULL we can print a message error or warning error like:
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	 * we can't use a ST like first instruction.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   975
	 * What do you think?
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   976
	 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   977
	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
   978
		(il_operand->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
   979
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'STN' 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
   980
	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
   981
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   982
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   983
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
   984
	/* 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
   985
	 *              NOT [<il_operand>]
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   986
	 *       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
   987
	 *       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
   988
	 */
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   989
	if (il_operand != NULL)
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   990
		STAGE3_ERROR(0, symbol, symbol, "'NOT' operator may not have an operand.");
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   991
	if (symbol->candidate_datatypes.size() == 0)
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   992
		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
   993
	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
   994
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *print_datatypes_error_c::visit(S_operator_c *symbol) {
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
   997
  /* TODO: what if this is a FB call ?? */
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
   998
	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
   999
		(il_operand->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
  1000
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'S' 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
  1001
	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
  1002
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1003
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1004
void *print_datatypes_error_c::visit(R_operator_c *symbol) {
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
  1005
  /* TODO: what if this is a FB call ?? */
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
  1006
	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
  1007
		(il_operand->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
  1008
		STAGE3_ERROR(0, symbol, symbol, "Data type mismatch for 'R' 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
  1009
	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
  1010
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1011
482
b62a5ecce54d Cleaning up some code.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
  1012
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
  1013
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
  1014
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
  1015
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
  1016
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
  1017
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
  1018
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
  1019
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
  1020
483
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 482
diff changeset
  1021
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
  1022
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
  1023
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
  1024
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
  1025
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
  1026
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
  1027
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
  1028
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
  1029
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
  1030
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
  1031
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
  1032
484
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1033
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
  1034
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
  1035
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
  1036
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
  1037
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
  1038
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
  1039
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1040
  
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
  1041
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1042
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1043
void *print_datatypes_error_c::handle_conditional_flow_control_IL_instruction(symbol_c *symbol, const char *oper) {
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1044
	if (NULL == symbol->datatype)
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1045
		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
  1046
	return NULL;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1047
}
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1048
487
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1049
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
  1050
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
  1051
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
  1052
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
  1053
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
  1054
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
  1055
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
  1056
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
  1057
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
  1058
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 486
diff changeset
  1059
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
  1060
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1061
/* 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
  1062
// 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
  1063
/* 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
  1064
// 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
  1065
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1066
/***************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1067
/* 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
  1068
/***************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1069
/***********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1070
/* 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
  1071
/***********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1072
485
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1073
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
  1074
	l_expr->accept(*this);
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1075
	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
  1076
	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
  1077
		(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
  1078
		(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
  1079
		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
  1080
        if (deprecated_operation)
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1081
                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
  1082
	return NULL;
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1083
}
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1084
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1085
835697564c6d Clean code for printing errors in expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1086
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
  1087
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
  1088
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
  1089
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
  1090
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
  1091
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
  1092
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
  1093
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
  1094
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
  1095
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
  1096
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
  1097
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
  1098
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
  1099
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
  1100
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
  1101
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1102
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1103
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
  1104
	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
  1105
	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
  1106
		(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
  1107
		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
  1108
	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
  1109
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1110
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1111
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1112
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
  1113
	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
  1114
	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
  1115
		(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
  1116
		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
  1117
	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
  1118
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1119
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1120
/* 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
  1121
/*    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
  1122
/* 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
  1123
// 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
  1124
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
  1125
	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
  1126
		/* 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
  1127
		/* 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
  1128
		/* 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
  1129
		/* 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
  1130
		/* 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
  1131
		/* 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
  1132
		/* 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
  1133
	};
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1134
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1135
	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
  1136
	return NULL;
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1137
}
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1138
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1139
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
  1140
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1141
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1142
/* 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
  1143
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1144
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1145
/*********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1146
/* 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
  1147
/*********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1148
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
  1149
	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
  1150
	symbol->r_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
  1151
	if ((NULL == symbol->l_exp->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	    (NULL == symbol->r_exp->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		(symbol->l_exp->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
  1154
		(symbol->r_exp->candidate_datatypes.size() > 0))
491
6f4083fe169e Edit error message.
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
  1155
		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
  1156
	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
  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
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
  1159
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1160
/*****************************************/
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1161
/* 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
  1162
/*****************************************/
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1163
/* 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
  1164
/*    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
  1165
/* 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
  1166
/* 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
  1167
// 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
  1168
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
  1169
	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
  1170
	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
  1171
	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
  1172
		/* 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
  1173
		/* 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
  1174
		/* 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
  1175
		/* 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
  1176
		/* 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
  1177
		/* 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
  1178
		/* 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
  1179
	};
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1180
	
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1181
	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
  1182
	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
  1183
}
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1184
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
  1185
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
  1186
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1187
/* 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
  1188
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1189
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1190
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
  1191
	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
  1192
	if ((NULL == symbol->expression->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1193
		(symbol->expression->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
  1194
		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'IF' 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
  1195
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1196
	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
  1197
		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
  1198
	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
  1199
		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
  1200
	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
  1201
		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
  1202
	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
  1203
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1204
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1205
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
  1206
	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
  1207
	if ((NULL == symbol->expression->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		(symbol->expression->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
  1209
		STAGE3_ERROR(0, symbol, symbol, "Invalid data type for 'ELSIF' 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
  1210
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
  1212
		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
  1213
	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
  1214
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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(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
  1218
	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
  1219
	if ((NULL == symbol->expression->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1220
		(symbol->expression->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
  1221
		STAGE3_ERROR(0, symbol, symbol, "'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
  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
	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
  1224
	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
  1225
		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
  1226
	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
  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
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
  1231
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1232
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1233
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
  1234
	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
  1235
	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
  1236
	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
  1237
	/* Control 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
  1238
	if ((NULL == symbol->control_variable->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		(symbol->control_variable->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
  1240
		STAGE3_ERROR(0, symbol, symbol, "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
  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
	/* BEG 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
  1243
	if ((NULL == symbol->beg_expression->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		(symbol->beg_expression->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
  1245
		STAGE3_ERROR(0, symbol, symbol, "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
  1246
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	/* END 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
  1248
	if ((NULL == symbol->end_expression->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		(symbol->end_expression->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
  1250
		STAGE3_ERROR(0, symbol, symbol, "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
  1251
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1252
	/* 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
  1253
	if ((NULL != symbol->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
  1254
		(NULL == symbol->by_expression->datatype) &&
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1255
		(symbol->end_expression->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
  1256
		STAGE3_ERROR(0, symbol, symbol, "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
  1257
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	/* 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
  1259
	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
  1260
		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
  1261
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1262
	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
  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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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
  1266
	symbol->expression->accept(*this);
514
c2880eba49a1 Fix printing of data type errors in while and repeat statements.
Mario de Sousa <msousa@fe.up.pt>
parents: 510
diff changeset
  1267
	if (!is_type_valid(symbol->expression->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
  1268
		STAGE3_ERROR(0, symbol, symbol, "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
  1269
		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
  1270
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
  1274
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *print_datatypes_error_c::visit(repeat_statement_c *symbol) {
514
c2880eba49a1 Fix printing of data type errors in while and repeat statements.
Mario de Sousa <msousa@fe.up.pt>
parents: 510
diff changeset
  1277
	if (!is_type_valid(symbol->expression->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
  1278
		STAGE3_ERROR(0, symbol, symbol, "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
  1279
		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
  1280
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
  1282
		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
  1283
	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
  1284
	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
  1285
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1289
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1290