stage3/fill_candidate_datatypes.cc
author Mario de Sousa <msousa@fe.up.pt>
Thu, 04 Oct 2012 18:54:15 +0100
changeset 671 d28c7ebaca21
parent 666 8ba9ec4bae50
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-2012  Mario de Sousa (msousa@fe.up.pt)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     5
 *  Copyright (C) 2012       Manuele Conti (manuele.conti@sirius-es.it)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     6
 *  Copyright (C) 2012       Matteo Facchinetti (matteo.facchinetti@sirius-es.it)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    34
541
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    35
/* TODO - things yet not checked by this data type checker...
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    36
 *
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    37
 * - check variable declarations
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    38
 * - check data type declarations
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    39
 * - check inside configurations (variable declarations)
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    40
 * - check SFC code
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    41
 * - must fix S and R IL functions (includes potientialy fixing stage4 code!) 
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    42
 */
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    43
f6208d457722 Add TODO list!
Mario de Sousa <msousa@fe.up.pt>
parents: 523
diff changeset
    44
552
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    45
/* NOTE: The algorithm implemented here assumes that flow control analysis has already been completed!
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    46
 *       BEFORE running this visitor, be sure to CALL the flow_control_analysis_c visitor!
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    47
 */
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    48
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    49
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
    50
/*
552
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    51
 *  Fill the candidate datatype list for all symbols that may legally 'have' a data type (e.g. variables, literals, function calls, expressions, etc.)
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    52
 * 
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    53
 *  The candidate datatype list will be filled with a list of all the data types that expression may legally take.
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    54
 *  For example, the very simple literal '0' (as in foo := 0), may represent a:
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 541
diff changeset
    55
 *    BOOL, BYTE, WORD, DWORD, LWORD, USINT, SINT, UINT, INT, UDINT, DINT, ULINT, LINT (as well as the SAFE versions of these data tyes too!)
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
    56
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    57
604
2989051a0a64 Fixing includes to define INTxx_MAX etc...
Mario de Sousa <msousa@fe.up.pt>
parents: 603
diff changeset
    58
#include <../main.hh>         /* required for UINT64_MAX, INT64_MAX, INT64_MIN, ... */
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
    59
#include "fill_candidate_datatypes.hh"
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
#include "datatype_functions.hh"
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
#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
    62
#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
    63
#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
    64
#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
    65
#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
    66
612
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 610
diff changeset
    67
#define GET_CVALUE(dtype, symbol)             ((symbol)->const_value._##dtype.value)
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 610
diff changeset
    68
#define VALID_CVALUE(dtype, symbol)           (symbol_c::cs_const_value == (symbol)->const_value._##dtype.status)
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 610
diff changeset
    69
#define IS_OVERFLOW(dtype, symbol)            (symbol_c::cs_overflow == (symbol)->const_value._##dtype.status)
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
    70
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
    71
/* set to 1 to see debug info during execution */
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
    72
static int debug = 0;
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
    73
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
fill_candidate_datatypes_c::fill_candidate_datatypes_c(symbol_c *ignore) {
661
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 652
diff changeset
    75
	il_operand = NULL;
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 652
diff changeset
    76
	prev_il_instruction = NULL;
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 652
diff changeset
    77
	search_varfb_instance_type = NULL;
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
    78
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    79
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    80
fill_candidate_datatypes_c::~fill_candidate_datatypes_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
    81
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    82
478
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
    83
symbol_c *fill_candidate_datatypes_c::widening_conversion(symbol_c *left_type, symbol_c *right_type, const struct widen_entry widen_table[]) {
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
    84
	int k;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    85
	/* find a widening table entry 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
    86
	for (k = 0; NULL != widen_table[k].left;  k++)
478
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
    87
		if ((typeid(*left_type) == typeid(*widen_table[k].left)) && (typeid(*right_type) == typeid(*widen_table[k].right)))
476
38d85e9a0507 Add check widening status for IL operator.
Manuele Conti <conti.ma@alice.it>
parents: 473
diff changeset
    88
                      return widen_table[k].result;
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
    89
	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
    90
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    91
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
    92
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
    93
/* add a data type to a candidate data type list, while guaranteeing no duplicate entries! */
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
    94
/* Returns true if it really did add the datatype to the list, or false if it was already present in the list! */
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
    95
bool fill_candidate_datatypes_c::add_datatype_to_candidate_list(symbol_c *symbol, symbol_c *datatype) {
478
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
    96
  /* If it is an invalid data type, do not insert!
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
    97
   * NOTE: it reduces overall code size to do this test here, instead of doing every time before calling the add_datatype_to_candidate_list() function. 
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
    98
   */
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
    99
  if (!is_type_valid(datatype)) /* checks for NULL and invalid_type_name_c */
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   100
    return false;
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 476
diff changeset
   101
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   102
  if (search_in_candidate_datatype_list(datatype, symbol->candidate_datatypes) >= 0) 
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   103
    /* already in the list, Just return! */
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   104
    return false;
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   105
  
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   106
  /* not yet in the candidate data type list, so we insert it now! */
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   107
  symbol->candidate_datatypes.push_back(datatype);
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   108
  return true;
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   109
}
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   110
    
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   111
    
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   112
bool fill_candidate_datatypes_c::add_2datatypes_to_candidate_list(symbol_c *symbol, symbol_c *datatype1, symbol_c *datatype2) {
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   113
  add_datatype_to_candidate_list(symbol, datatype1);
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   114
  add_datatype_to_candidate_list(symbol, datatype2);
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   115
  return true;
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   116
}
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   117
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   118
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   119
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   120
void fill_candidate_datatypes_c::remove_incompatible_datatypes(symbol_c *symbol) {
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   121
  #ifdef __REMOVE__
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   122
    #error __REMOVE__ macro already exists. Choose another name!
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   123
  #endif
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   124
  #define __REMOVE__(datatype)\
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   125
      remove_from_candidate_datatype_list(&search_constant_type_c::datatype,       symbol->candidate_datatypes);\
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   126
      remove_from_candidate_datatype_list(&search_constant_type_c::safe##datatype, symbol->candidate_datatypes);
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   127
  
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   128
  {/* Remove unsigned data types */
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   129
    uint64_t value = 0;
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   130
    if (VALID_CVALUE( uint64, symbol)) value = GET_CVALUE(uint64, symbol);
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   131
    if (IS_OVERFLOW ( uint64, symbol)) value = (uint64_t)UINT32_MAX + (uint64_t)1;
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   132
    
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   133
    if (value > 1          )          {__REMOVE__(bool_type_name);}
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   134
    if (value > UINT8_MAX  )          {__REMOVE__(usint_type_name);  __REMOVE__( byte_type_name);}
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   135
    if (value > UINT16_MAX )          {__REMOVE__( uint_type_name);  __REMOVE__( word_type_name);}
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   136
    if (value > UINT32_MAX )          {__REMOVE__(udint_type_name);  __REMOVE__(dword_type_name);}
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   137
    if (IS_OVERFLOW( uint64, symbol)) {__REMOVE__(ulint_type_name);  __REMOVE__(lword_type_name);}
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   138
  }
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   139
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   140
  {/* Remove signed data types */
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   141
    int64_t value = 0;
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   142
    if (VALID_CVALUE(  int64, symbol)) value = GET_CVALUE(int64, symbol);
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   143
    if (IS_OVERFLOW (  int64, symbol)) value = (int64_t)INT32_MAX + (int64_t)1;
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   144
    
609
9ab033d2bb55 signed integer limits do not affect ANY_INT constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   145
    if ((value <  INT8_MIN) || (value >  INT8_MAX)) {__REMOVE__(sint_type_name);}
9ab033d2bb55 signed integer limits do not affect ANY_INT constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   146
    if ((value < INT16_MIN) || (value > INT16_MAX)) {__REMOVE__( int_type_name);}
9ab033d2bb55 signed integer limits do not affect ANY_INT constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   147
    if ((value < INT32_MIN) || (value > INT32_MAX)) {__REMOVE__(dint_type_name);}
9ab033d2bb55 signed integer limits do not affect ANY_INT constant values.
Mario de Sousa <msousa@fe.up.pt>
parents: 607
diff changeset
   148
    if (IS_OVERFLOW( int64, symbol))                {__REMOVE__(lint_type_name);}
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   149
  }
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   150
    
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   151
  {/* Remove floating point data types */
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   152
    real64_t value = 0;
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   153
    if (VALID_CVALUE( real64, symbol)) value = GET_CVALUE(real64, symbol);
610
50b708dff319 fix bug: remove REAL from candidate datatypes when real constant has overflowed.
Mario de Sousa <msousa@fe.up.pt>
parents: 609
diff changeset
   154
    if (IS_OVERFLOW ( real64, symbol)) value = (real64_t)REAL32_MAX + (real64_t)1;
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   155
    if (value >  REAL32_MAX )         {__REMOVE__( real_type_name);}
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   156
    if (value < -REAL32_MAX )         {__REMOVE__( real_type_name);}
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   157
    if (IS_OVERFLOW( real64, symbol)) {__REMOVE__(lreal_type_name);}
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   158
  }
607
be9ba3531afb cleaning up code. Changing HUGE_VAL to INFINITY.
Mario de Sousa <msousa@fe.up.pt>
parents: 605
diff changeset
   159
  #undef __REMOVE__
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   160
}
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   161
    
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   162
420
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   163
/* returns true if compatible function/FB invocation, otherwise returns false */
424
43d73e28eca8 Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents: 422
diff changeset
   164
/* Assumes that the candidate_datatype lists of all the parameters being passed haved already been filled in */
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: 442
diff changeset
   165
/*
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: 442
diff changeset
   166
 * All parameters being passed to the called function MUST be in the parameter list to which f_call points to!
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: 442
diff changeset
   167
 * This means that, for non formal function calls in IL, de current (default value) must be artificially added to the
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: 442
diff changeset
   168
 * beginning of the parameter list BEFORE calling handle_function_call().
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: 442
diff changeset
   169
 */
420
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   170
bool fill_candidate_datatypes_c::match_nonformal_call(symbol_c *f_call, symbol_c *f_decl) {
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   171
	symbol_c *call_param_value,  *param_datatype;
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
   172
	identifier_c *param_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
   173
	function_param_iterator_c       fp_iterator(f_decl);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   174
	function_call_param_iterator_c fcp_iterator(f_call);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   175
	int extensible_parameter_highest_index = -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
   176
	unsigned int i;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   177
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   178
	/* Iterating through the non-formal parameters of the function call */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   179
	while((call_param_value = fcp_iterator.next_nf()) != 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
   180
		/* Iterate to the next parameter of the function being called.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   181
		 * Get the name of that parameter, and ignore if EN or ENO.
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   182
		 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   183
		do {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   184
			param_name = fp_iterator.next();
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   185
			/* If there is no other parameter declared, then we are passing too many parameters... */
420
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   186
			if(param_name == NULL) return false;
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
   187
		} while ((strcmp(param_name->value, "EN") == 0) || (strcmp(param_name->value, "ENO") == 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
   188
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   189
		/* TODO: verify if it is lvalue when INOUT or OUTPUT parameters! */
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
   190
		/* Get the parameter type */
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   191
		param_datatype = base_type(fp_iterator.param_type());
420
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   192
		
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   193
		/* check whether one of the candidate_data_types of the value being passed is the same as the param_type */
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   194
		if (search_in_candidate_datatype_list(param_datatype, call_param_value->candidate_datatypes) < 0)
442
bd5998ee8876 Code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   195
			return false; /* return false if param_type not in the list! */
420
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   196
	}
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   197
	/* call is compatible! */
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   198
	return true;
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   199
}
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   200
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   201
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   202
420
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   203
/* returns true if compatible function/FB invocation, otherwise returns false */
424
43d73e28eca8 Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents: 422
diff changeset
   204
/* Assumes that the candidate_datatype lists of all the parameters being passed haved already been filled in */
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   205
bool fill_candidate_datatypes_c::match_formal_call(symbol_c *f_call, symbol_c *f_decl, symbol_c **first_param_datatype) {
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   206
	symbol_c *call_param_value, *call_param_name, *param_datatype;
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
   207
	symbol_c *verify_duplicate_param;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   208
	identifier_c *param_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
   209
	function_param_iterator_c       fp_iterator(f_decl);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   210
	function_call_param_iterator_c fcp_iterator(f_call);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   211
	int extensible_parameter_highest_index = -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
   212
	identifier_c *extensible_parameter_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
   213
	unsigned int i;
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   214
	bool is_first_param = true;
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
   215
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   216
	/* Iterating through the formal parameters of the function call */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   217
	while((call_param_name = fcp_iterator.next_f()) != 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
   218
		/* Obtaining the value being passed in the function call */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   219
		call_param_value = fcp_iterator.get_current_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
   220
		/* the following should never occur. If it does, then we have a bug in our 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
   221
		if (NULL == call_param_value) ERROR;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   222
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   223
		/* 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
   224
		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
   225
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
   226
		/* Checking if there are duplicated parameter values */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   227
		verify_duplicate_param = fcp_iterator.search_f(call_param_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
   228
		if(verify_duplicate_param != call_param_value)
420
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   229
			return false;
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
   230
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   231
		/* Obtaining the type of the value being passed in the function call */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   232
		std::vector <symbol_c *>&call_param_types = call_param_value->candidate_datatypes;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   233
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   234
		/* Find the corresponding parameter in function declaration */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   235
		param_name = fp_iterator.search(call_param_name);
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   236
		if(param_name == NULL) return false;
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   237
		/* Get the parameter data type */
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   238
		param_datatype = base_type(fp_iterator.param_type());
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   239
		/* 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
   240
		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
   241
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   242
		/* 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
   243
		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
   244
			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
   245
			    (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
   246
				return false;
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   247
		} 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
   248
			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
   249
				return false;
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   250
		} 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
   251
		
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   252
		/* check whether one of the candidate_data_types of the value being passed is the same as the param_type */
449
3c6225521059 Semantic verification: Add compatibility check for parameter direction in function invocation.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   253
		if (search_in_candidate_datatype_list(param_datatype, call_param_types) < 0)
442
bd5998ee8876 Code cleanup.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   254
			return false; /* return false if param_type not in the list! */
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   255
		
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   256
		/* If this is the first parameter, then copy the datatype to *first_param_datatype */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   257
		if (is_first_param)
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   258
			if (NULL != first_param_datatype)
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   259
				*first_param_datatype = param_datatype;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   260
		is_first_param = false;
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   261
	}
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   262
	/* call is compatible! */
420
866eb35e4e14 Fix search_varfb_instance_decl to be able to find variables and FB when only given an identifier.
Mario de Sousa <msousa@fe.up.pt>
parents: 419
diff changeset
   263
	return true;
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
   264
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   265
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   266
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   267
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
   268
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   269
/* Handle a generic function call!
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   270
 * Assumes that the parameter_list containing the values being passed in this function invocation
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   271
 * has already had all the candidate_datatype lists filled in!
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   272
 *
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   273
 * All parameters being passed to the called function MUST be in the parameter list to which f_call points to!
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   274
 * This means that, for non formal function calls in IL, de current (default value) must be artificially added to the
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   275
 * beginning of the parameter list BEFORE calling handle_function_call().
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   276
 */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   277
/*
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   278
typedef struct {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   279
  symbol_c *function_name,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   280
  symbol_c *nonformal_operand_list,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   281
  symbol_c *   formal_operand_list,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   282
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   283
  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: 437
diff changeset
   284
  symbol_c &*called_function_declaration,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   285
  int      &extensible_param_count
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   286
} generic_function_call_t;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   287
*/
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   288
/*
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   289
void narrow_candidate_datatypes_c::narrow_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: 437
diff changeset
   290
void *fill_candidate_datatypes_c::handle_function_call(symbol_c *f_call, symbol_c *function_name, invocation_type_t invocation_type,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   291
                                                       std::vector <symbol_c *> *candidate_datatypes,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   292
                                                       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: 437
diff changeset
   293
  */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   294
void fill_candidate_datatypes_c::handle_function_call(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: 437
diff changeset
   295
	function_declaration_c *f_decl;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   296
	list_c *parameter_list;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   297
	list_c *parameter_candidate_datatypes;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   298
	symbol_c *returned_parameter_type;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   299
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   300
	if (debug) std::cout << "function()\n";
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   301
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   302
	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: 437
diff changeset
   303
	function_symtable_t::iterator upper = function_symtable.upper_bound(fcall_data.function_name);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   304
	/* If the name of the function being called is not found in the function symbol table, then this is an invalid call */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   305
	/* Since the lexical parser already checks for this, then if this occurs then we have an internal compiler error. */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   306
	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: 437
diff changeset
   307
	
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   308
	/* Look for all compatible function declarations, and add their return datatypes 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   309
	 * to the candidate_datatype list of this function invocation. 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   310
	 *
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   311
	 * If only one function exists, we add its return datatype to the candidate_datatype list,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   312
	 * even if the parameters passed to it are invalid.
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   313
	 * This guarantees that the remainder of the expression in which the function call is inserted
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   314
	 * is treated as if the function call returns correctly, and therefore does not generate
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   315
	 * spurious error messages.
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   316
	 * Even if the parameters to the function call are invalid, doing this is still safe, as the 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   317
	 * expressions inside the function call will themselves have erros and will  guarantee that 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   318
	 * compilation is aborted in stage3 (in print_datatypes_error_c).
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   319
	 */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   320
	if (function_symtable.multiplicity(fcall_data.function_name) == 1) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   321
		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: 437
diff changeset
   322
		returned_parameter_type = base_type(f_decl->type_name);
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   323
		if (add_datatype_to_candidate_list(fcall, returned_parameter_type))
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   324
			/* we only add it to the function declaration list if this entry was not already present in the candidate datatype list! */
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   325
			fcall_data.candidate_functions.push_back(f_decl);
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   326
		
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   327
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   328
	for(; lower != upper; lower++) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   329
		bool compatible = false;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   330
		
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   331
		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: 437
diff changeset
   332
		/* Check if function declaration in symbol_table is compatible with parameters */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   333
		if (NULL != fcall_data.nonformal_operand_list) compatible=match_nonformal_call(fcall, f_decl);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   334
		if (NULL != fcall_data.   formal_operand_list) compatible=   match_formal_call(fcall, f_decl);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   335
		if (compatible) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   336
			/* Add the data type returned by the called functions. 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   337
			 * However, only do this if this data type is not already present in the candidate_datatypes list_c
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   338
			 */
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   339
			returned_parameter_type = base_type(f_decl->type_name);		
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   340
			if (add_datatype_to_candidate_list(fcall, returned_parameter_type))
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   341
				/* we only add it to the function declaration list if this entry was not already present in the candidate datatype list! */
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   342
				fcall_data.candidate_functions.push_back(f_decl);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   343
		}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   344
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   345
	if (debug) std::cout << "end_function() [" << fcall->candidate_datatypes.size() << "] result.\n";
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   346
	return;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   347
}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   348
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   349
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   350
/* handle implicit FB call in IL.
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: 447
diff changeset
   351
 * e.g.  CLK ton_var
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   352
 *        CU counter_var
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   353
 */
489
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
   354
void *fill_candidate_datatypes_c::handle_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) {
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   355
	symbol_c *fb_type_id = search_varfb_instance_type->get_basetype_id(il_operand);
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   356
  	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   357
	if (NULL == fb_type_id) ERROR;
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   358
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   359
	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id);
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   360
	if (function_block_type_symtable.end_value() == fb_decl)
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   361
		/* The il_operand is not the name of a FB instance. Most probably it is the name of a variable of some other type.
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   362
		 * this is a semantic error.
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   363
		 */
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   364
		fb_decl = NULL;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   365
	
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   366
	/* The narrow_candidate_datatypes_c does not rely on this called_fb_declaration pointer being == NULL to conclude that
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   367
	 * we have a datatype incompatibility error, so we set it to fb_decl to allow the print_datatype_error_c to print out
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   368
	 * more informative error messages!
450
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   369
	 */
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   370
	called_fb_declaration = fb_decl;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   371
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   372
	/* This implicit FB call does not change the value stored in the current/default IL variable */
456
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   373
	/* It does, however, require that the datatype be compatible with the input parameter of the FB being called. 
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   374
	 * If we were to follow the filling & narrowing algorithm correctly (implemented in fill_candidate_datatypes_c
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   375
	 * & narrow_candidate_datatypes_c respectively), we should be restricting the candidate_datatpes to the datatypes
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   376
	 * that are compatible to the FB call. 
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   377
	 * However, doing the above will often result in some very confusing error messages for the user, especially in the case
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   378
	 * in which the FB call is wrong, so the resulting cadidate datatypes is an empty list. In this case, the user would see
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   379
	 * many error messages related to the IL instructions that follow the FB call, even though those IL instructions may be perfectly
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   380
	 * correct.
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   381
	 * For now, we will simply let the narrow_candidate_datatypes_c verify if the datatypes are compatible (something that should be done
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   382
	 * here).
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   383
	 */
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   384
	if (NULL != prev_il_instruction)
467
4910eaa1206a Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents: 465
diff changeset
   385
		il_instruction->candidate_datatypes = prev_il_instruction->candidate_datatypes; 
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   386
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   387
	if (debug) std::cout << "handle_implicit_il_fb_call() [" << prev_il_instruction->candidate_datatypes.size() << "] ==> " << il_instruction->candidate_datatypes.size() << " result.\n";
489
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
   388
	return NULL;
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   389
}
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   390
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   391
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   392
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   393
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   394
/* handle a binary IL operator, like ADD, SUB, etc... */
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   395
void *fill_candidate_datatypes_c::handle_binary_operator(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) {
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   396
	if (NULL == l_expr) /* if no prev_il_instruction */
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   397
		return NULL; 
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   398
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   399
	for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++)
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   400
		for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++)
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   401
			/* NOTE: add_datatype_to_candidate_list() will only really add the datatype if it is != NULL !!! */
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   402
			add_datatype_to_candidate_list(symbol, widening_conversion(l_expr->candidate_datatypes[i], r_expr->candidate_datatypes[j], widen_table));
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   403
	remove_incompatible_datatypes(symbol);
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   404
	if (debug) std::cout <<  "[" << l_expr->candidate_datatypes.size() << "," << r_expr->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   405
	return NULL;
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   406
}
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   407
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   408
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   409
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   410
/* handle a binary ST expression, like '+', '-', etc... */
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   411
void *fill_candidate_datatypes_c::handle_binary_expression(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) {
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   412
	l_expr->accept(*this);
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   413
	r_expr->accept(*this);
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   414
	return handle_binary_operator(widen_table, symbol, l_expr, r_expr);
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   415
}
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   416
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   417
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   418
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   419
/* handle the two equality comparison operations, i.e. = (euqal) and != (not equal) */
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   420
/* This function is special, as it will also allow enumeration data types to be compared, with the result being a BOOL data type!
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   421
 * This possibility os not expressed in the 'widening' tables, so we need to hard code it here
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   422
 */
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   423
void *fill_candidate_datatypes_c::handle_equality_comparison(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr) {
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   424
	search_base_type_c search_base_type;
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   425
	handle_binary_expression(widen_table, symbol, l_expr, r_expr);
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   426
	for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++)
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   427
		for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++) {
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   428
			if ((l_expr->candidate_datatypes[i] == r_expr->candidate_datatypes[j]) && search_base_type.type_is_enumerated(l_expr->candidate_datatypes[i]))
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   429
				add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name);
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   430
		}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   431
	return NULL;
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   432
}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   433
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
   434
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   435
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
/* 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
   437
symbol_c *fill_candidate_datatypes_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
   438
	/* 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
   439
	 *       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
   440
	 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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 == 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
   442
	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
   443
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   444
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   445
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   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
/* 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
   450
/******************************/
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   451
#define sizeoftype(symbol) get_sizeof_datatype_c::getsize(symbol)
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   452
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   453
void *fill_candidate_datatypes_c::handle_any_integer(symbol_c *symbol) {
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   454
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name,  &search_constant_type_c::safebool_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   455
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::byte_type_name,  &search_constant_type_c::safebyte_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   456
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::word_type_name,  &search_constant_type_c::safeword_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   457
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::dword_type_name, &search_constant_type_c::safedword_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   458
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lword_type_name, &search_constant_type_c::safelword_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   459
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::sint_type_name,  &search_constant_type_c::safesint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   460
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::int_type_name,   &search_constant_type_c::safeint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   461
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::dint_type_name,  &search_constant_type_c::safedint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   462
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lint_type_name,  &search_constant_type_c::safelint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   463
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::usint_type_name, &search_constant_type_c::safeusint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   464
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::uint_type_name,  &search_constant_type_c::safeuint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   465
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::udint_type_name, &search_constant_type_c::safeudint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   466
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::ulint_type_name, &search_constant_type_c::safeulint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   467
	remove_incompatible_datatypes(symbol);
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   468
	if (debug) std::cout << "ANY_INT [" << symbol->candidate_datatypes.size()<< "]" << std::endl;
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   469
	return NULL;
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   470
}
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   471
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   473
488
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   474
void *fill_candidate_datatypes_c::handle_any_real(symbol_c *symbol) {
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   475
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::real_type_name,  &search_constant_type_c::safereal_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   476
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name, &search_constant_type_c::safelreal_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   477
	remove_incompatible_datatypes(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
   478
	if (debug) std::cout << "ANY_REAL [" << symbol->candidate_datatypes.size() << "]" << std::endl;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   480
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   481
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   482
488
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   483
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   484
void *fill_candidate_datatypes_c::handle_any_literal(symbol_c *symbol, symbol_c *symbol_value, symbol_c *symbol_type) {
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   485
	symbol_value->accept(*this);
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   486
	if (search_in_candidate_datatype_list(symbol_type, symbol_value->candidate_datatypes) >= 0)
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   487
		add_datatype_to_candidate_list(symbol, symbol_type);
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   488
	remove_incompatible_datatypes(symbol);
643
1cc0e1ca2aad Fix constant folding: now handles INT_MIN and neg_integer_c correctly.
Mario de Sousa <msousa@fe.up.pt>
parents: 612
diff changeset
   489
	if (debug) std::cout << "ANY_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
488
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   490
	return NULL;
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   491
}
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   492
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   493
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   494
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   495
void *fill_candidate_datatypes_c::visit(    real_c *symbol) {return handle_any_real(symbol);}
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   496
void *fill_candidate_datatypes_c::visit(neg_real_c *symbol) {return handle_any_real(symbol);}
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   497
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   498
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   499
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
   500
void *fill_candidate_datatypes_c::visit(neg_integer_c *symbol) {
650
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
   501
	/* Please read the comment in neg_expression_c method, as it also applies here */
603
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   502
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::int_type_name, &search_constant_type_c::safeint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   503
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::sint_type_name, &search_constant_type_c::safesint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   504
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::dint_type_name, &search_constant_type_c::safedint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   505
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::lint_type_name, &search_constant_type_c::safelint_type_name);
a45a62dd6df9 Add remove_from_candidate_datatype_list method using constant_folding results.
Manuele Conti <conti.ma@alice.it>
parents: 558
diff changeset
   506
	remove_incompatible_datatypes(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
   507
	if (debug) std::cout << "neg ANY_INT [" << symbol->candidate_datatypes.size() << "]" << std::endl;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   508
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   509
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   510
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   511
488
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   512
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   513
void *fill_candidate_datatypes_c::visit(integer_c        *symbol) {return handle_any_integer(symbol);}
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   514
void *fill_candidate_datatypes_c::visit(binary_integer_c *symbol) {return handle_any_integer(symbol);}
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   515
void *fill_candidate_datatypes_c::visit(octal_integer_c  *symbol) {return handle_any_integer(symbol);}
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   516
void *fill_candidate_datatypes_c::visit(hex_integer_c    *symbol) {return handle_any_integer(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
   517
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   518
488
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   519
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   520
// SYM_REF2(integer_literal_c, type, value)
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   521
/*
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   522
 * integer_literal:
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   523
 *   integer_type_name '#' signed_integer
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   524
 * | integer_type_name '#' binary_integer
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   525
 * | integer_type_name '#' octal_integer
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   526
 * | integer_type_name '#' hex_integer
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   527
 */
488
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   528
void *fill_candidate_datatypes_c::visit(   integer_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);}
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   529
void *fill_candidate_datatypes_c::visit(      real_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);}
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   530
void *fill_candidate_datatypes_c::visit(bit_string_literal_c *symbol) {return handle_any_literal(symbol, symbol->value, symbol->type);}
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   531
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   532
void *fill_candidate_datatypes_c::visit(   boolean_literal_c *symbol) {
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   533
	if (NULL != symbol->type) return handle_any_literal(symbol, symbol->value, symbol->type);
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   534
427
eb9bc99944d9 Better error reporting in function invocations, and in invalid literal values.
Mario de Sousa <msousa@fe.up.pt>
parents: 426
diff changeset
   535
	symbol->value->accept(*this);
488
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   536
	symbol->candidate_datatypes = symbol->value->candidate_datatypes;
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   537
	return NULL;
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   538
}
c833f83aac8c Some code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 487
diff changeset
   539
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   540
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   541
void *fill_candidate_datatypes_c::visit(boolean_true_c *symbol) {
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   542
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name);
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
   543
	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
   544
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   545
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   546
void *fill_candidate_datatypes_c::visit(boolean_false_c *symbol) {
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   547
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::bool_type_name, &search_constant_type_c::safebool_type_name);
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
   548
	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
   549
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   550
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   551
/*******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   552
/* 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
   553
/*******************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *fill_candidate_datatypes_c::visit(double_byte_character_string_c *symbol) {
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   555
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::wstring_type_name, &search_constant_type_c::safewstring_type_name);
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
   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 *fill_candidate_datatypes_c::visit(single_byte_character_string_c *symbol) {
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   560
	add_2datatypes_to_candidate_list(symbol, &search_constant_type_c::string_type_name, &search_constant_type_c::safestring_type_name);
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
   561
	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
   562
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   566
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   567
/************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   568
/* B 1.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
   569
/************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   570
void *fill_candidate_datatypes_c::visit(duration_c *symbol) {
437
0e09a8840c92 Add TODO comment, and delete unused debugging code.
Mario de Sousa <msousa@fe.up.pt>
parents: 435
diff changeset
   571
	/* TODO: check whether the literal follows the rules specified in section '2.2.3.1 Duration' of the standard! */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   572
	
472
d26759a2274a Clean up code, and add support for 'safe' version of literals.
Mario de Sousa <msousa@fe.up.pt>
parents: 470
diff changeset
   573
	add_datatype_to_candidate_list(symbol, symbol->type_name);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   574
	if (debug) std::cout << "TIME_LITERAL [" << symbol->candidate_datatypes.size() << "]\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   576
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   577
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   578
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   579
/* 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
   580
/************************************/
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   581
void *fill_candidate_datatypes_c::visit(time_of_day_c   *symbol) {add_datatype_to_candidate_list(symbol, symbol->type_name); return NULL;}
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   582
void *fill_candidate_datatypes_c::visit(date_c          *symbol) {add_datatype_to_candidate_list(symbol, symbol->type_name); return NULL;}
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   583
void *fill_candidate_datatypes_c::visit(date_and_time_c *symbol) {add_datatype_to_candidate_list(symbol, symbol->type_name); return NULL;}
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
   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.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
   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
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   590
/********************************/
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   591
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   592
/* simple_specification ASSIGN constant */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   593
// SYM_REF2(simple_spec_init_c, simple_specification, constant)
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   594
void *fill_candidate_datatypes_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: 490
diff changeset
   595
	if (NULL != symbol->constant) symbol->constant->accept(*this);
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   596
	add_datatype_to_candidate_list(symbol->simple_specification, base_type(symbol->simple_specification));
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   597
	symbol->candidate_datatypes = symbol->simple_specification->candidate_datatypes;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   598
	/* NOTE: Even if the constant and the type are of incompatible data types, we let the
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   599
	 *       simple_spec_init_c object inherit the data type of the type declaration (simple_specification)
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   600
	 *       This will let us produce more informative error messages when checking data type compatibility
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   601
	 *       with located variables (AT %QW3.4 : WORD).
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   602
	 */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   603
	// if (NULL != symbol->constant) intersect_candidate_datatype_list(symbol /*origin, dest.*/, symbol->constant /*with*/);
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   604
	return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   605
}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   606
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   607
/*  signed_integer DOTDOT signed_integer */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   608
// SYM_REF2(subrange_c, lower_limit, upper_limit)
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   609
void *fill_candidate_datatypes_c::visit(subrange_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
   610
	symbol->lower_limit->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
   611
	symbol->upper_limit->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
   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
	for (unsigned int u = 0; u < symbol->upper_limit->candidate_datatypes.size(); u++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		for(unsigned int l = 0; l < symbol->lower_limit->candidate_datatypes.size(); l++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			if (is_type_equal(symbol->upper_limit->candidate_datatypes[u], symbol->lower_limit->candidate_datatypes[l]))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   616
				add_datatype_to_candidate_list(symbol, symbol->lower_limit->candidate_datatypes[l]);
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
   617
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   620
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
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: 442
diff changeset
   622
/*  TYPE type_declaration_list END_TYPE */
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: 442
diff changeset
   623
// SYM_REF1(data_type_declaration_c, type_declaration_list)
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: 442
diff changeset
   624
/* NOTE: Not required. already handled by iterator_visitor_c base class */
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: 442
diff changeset
   625
/*
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
   626
void *fill_candidate_datatypes_c::visit(data_type_declaration_c *symbol) {
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: 442
diff changeset
   627
	symbol->type_declaration_list->accept(*this);
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: 442
diff changeset
   628
	return NULL;
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: 442
diff changeset
   629
}
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: 442
diff changeset
   630
*/
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
   631
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   632
void *fill_candidate_datatypes_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
   633
	symbol_c *enumerated_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
   634
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   635
	if (NULL != symbol->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
   636
		enumerated_type = symbol->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
   637
	else {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   638
		enumerated_type = enumerated_value_symtable.find_value(symbol->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
   639
		if (enumerated_type == enumerated_value_symtable.end_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
   640
			enumerated_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
   641
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   642
	enumerated_type = base_type(enumerated_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
   643
	if (NULL != enumerated_type)
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   644
		add_datatype_to_candidate_list(symbol, enumerated_type);
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
   645
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   646
	if (debug) std::cout << "ENUMERATE [" << symbol->candidate_datatypes.size() << "]\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   647
	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
   648
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   649
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   650
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   651
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   652
/* 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
   653
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   654
void *fill_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   655
	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol)); /* will only add if non NULL */
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
   656
	if (debug) std::cout << "VAR [" << symbol->candidate_datatypes.size() << "]\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   658
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   659
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   660
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
   661
/********************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   663
/********************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *fill_candidate_datatypes_c::visit(direct_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
   665
	/* Comment added by mario:
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	 * The following code is safe, actually, as the lexical parser guarantees the correct IEC61131-3 syntax was 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
   667
	 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	/* However, we should probably add an assertion in case we later change the lexical parser! */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	/* if (symbol->value == NULL) ERROR;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	 * if (symbol->value[0] == '\0') ERROR;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	 * if (symbol->value[1] == '\0') ERROR;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	switch (symbol->value[2]) {
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   674
		case 'x': case 'X': /* bit   -  1 bit  */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name);  break;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   675
		case 'b': case 'B': /* byte  -  8 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::byte_type_name);  break;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   676
		case 'w': case 'W': /* word  - 16 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::word_type_name);  break;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   677
		case 'd': case 'D': /* dword - 32 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::dword_type_name); break;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   678
		case 'l': case 'L': /* lword - 64 bits */ add_datatype_to_candidate_list(symbol, &search_constant_type_c::lword_type_name); break;
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   679
        	          /* if none of the above, then the empty string was used <=> boolean */
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   680
		default:                        add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name);  break;
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
   681
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   683
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   684
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   685
/*************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   686
/* 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
   687
/*************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/*  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
   689
// 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
   690
void *fill_candidate_datatypes_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
   691
	/* get the declaration of the data type __stored__ in the array... */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   692
	/* if we were to want the data type of the array itself, then we should call_param_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
   693
	 * search_varfb_instance_type->get_basetype_decl(symbol->subscripted_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
   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
	symbol_c *result = search_varfb_instance_type->get_basetype_decl(symbol);
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   696
	if (NULL != result) add_datatype_to_candidate_list(symbol, result);
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
   697
	
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   698
	/* recursively call the subscript list, so we can check the data types of the expressions used for the subscripts */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   700
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   701
	if (debug) std::cout << "ARRAY_VAR [" << symbol->candidate_datatypes.size() << "]\n";	
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
   703
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   707
// SYM_LIST(subscript_list_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
   708
/* NOTE: we inherit from iterator visitor, so we do not need to implement this method... */
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   709
// void *fill_candidate_datatypes_c::visit(subscript_list_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
   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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/*  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
   713
/*  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
   714
 *           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
   715
 *           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
   716
 *           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
   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
// 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
   719
/* NOTE: We do not need to recursively determine the data types of each field_selector, as the 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
   720
 * will do that for us. So we determine the candidate datatypes only for the full 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
   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
void *fill_candidate_datatypes_c::visit(structured_variable_c *symbol) {
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   723
	add_datatype_to_candidate_list(symbol, search_varfb_instance_type->get_basetype_decl(symbol));  /* will only add if non NULL */
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
   724
	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
   725
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   727
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   728
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   729
/******************************************/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   730
/* 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: 490
diff changeset
   731
/******************************************/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   732
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   733
void *fill_candidate_datatypes_c::visit(var1_list_c *symbol) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   734
#if 0   /* We don't really need to set the datatype of each variable. We just check the declaration itself! */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   735
  for(int i = 0; i < symbol->n; i++) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   736
    add_datatype_to_candidate_list(symbol->elements[i], search_varfb_instance_type->get_basetype_decl(symbol->elements[i])); /* will only add if non NULL */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   737
  }
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   738
#endif
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   739
  return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   740
}  
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   741
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   742
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   743
/*  AT direct_variable */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   744
// 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: 490
diff changeset
   745
void *fill_candidate_datatypes_c::visit(location_c *symbol) {
558
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   746
 /* This is a special situation. 
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   747
  *
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   748
  * The reason is that a located variable may be declared to be of any data type, as long as the size
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   749
  * matches the location (lines 1 3 and 4 of table 17). For example:
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   750
  *   var1 AT %MB42.0 : BYTE;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   751
  *   var1 AT %MB42.1 : SINT;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   752
  *   var1 AT %MB42.2 : USINT;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   753
  *   var1 AT %MW64   : INT;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   754
  *   var1 AT %MD56   : DINT;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   755
  *   var1 AT %MD57   : REAL;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   756
  *  are all valid!!
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   757
  *
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   758
  *  However, when used inside an expression, the direct variable (uses the same syntax as the location
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   759
  *  of a located variable) is limited to the following (ANY_BIT) data types:
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   760
  *    %MX --> BOOL
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   761
  *    %MB --> BYTE
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   762
  *    %MW --> WORD
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   763
  *    %MD --> DWORD
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   764
  *    %ML --> LWORD
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   765
  *
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   766
  *  So, in order to be able to analyse expressions with direct variables
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   767
  *   e.g:  var1 := 66 OR %MW34
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   768
  *  where the direct variable may only take the ANY_BIT data types, the fill_candidate_datatypes_c
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   769
  *  considers that only the ANY_BIT data types are allowed for a direct variable.
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   770
  *  However, it appears from the examples in the standard (lines 1 3 and 4 of table 17)
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   771
  *  a location may have any data type (presumably as long as the size in bits match).
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   772
  *  For this reason, a location_c may have more allowable data types than a direct_variable_c
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   773
  */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   774
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   775
	symbol->direct_variable->accept(*this);
558
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   776
	for (unsigned int i = 0; i < symbol->direct_variable->candidate_datatypes.size(); i++) {
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   777
        	switch (get_sizeof_datatype_c::getsize(symbol->direct_variable->candidate_datatypes[i])) {
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   778
			case  1: /* bit   -  1 bit  */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   779
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::bool_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   780
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safebool_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   781
					break;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   782
			case  8: /* byte  -  8 bits */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   783
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::byte_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   784
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safebyte_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   785
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::sint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   786
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safesint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   787
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::usint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   788
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safeusint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   789
					break;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   790
			case 16: /* word  - 16 bits */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   791
	 				add_datatype_to_candidate_list(symbol, &search_constant_type_c::word_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   792
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safeword_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   793
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::int_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   794
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safeint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   795
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::uint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   796
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safeuint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   797
					break;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   798
			case 32: /* dword - 32 bits */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   799
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::dword_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   800
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safedword_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   801
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::dint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   802
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safedint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   803
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::udint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   804
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safeudint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   805
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::real_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   806
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safereal_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   807
					break;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   808
			case 64: /* lword - 64 bits */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   809
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::lword_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   810
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safelword_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   811
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::lint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   812
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safelint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   813
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::ulint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   814
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safeulint_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   815
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::lreal_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   816
					add_datatype_to_candidate_list(symbol, &search_constant_type_c::safelreal_type_name);
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   817
					break;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   818
			default: /* if none of the above, then no valid datatype allowed... */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   819
					break;
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   820
		} /* switch() */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   821
	} /* for */
9273dfc5fa7c Located variables may have other data types besides ANY_BIT.
mjsousa <msousa@fe.up.pt>
parents: 552
diff changeset
   822
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   823
	return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   824
}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   825
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   826
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   827
/*  [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: 490
diff changeset
   828
/* variable_name -> may be NULL ! */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   829
// 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: 490
diff changeset
   830
void *fill_candidate_datatypes_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: 490
diff changeset
   831
  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: 490
diff changeset
   832
  symbol->location->accept(*this);
523
773303b7f31f Remove potential access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   833
  if (NULL != symbol->variable_name) {
773303b7f31f Remove potential access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   834
    symbol->variable_name->candidate_datatypes = symbol->location->candidate_datatypes;
773303b7f31f Remove potential access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   835
    intersect_candidate_datatype_list(symbol->variable_name /*origin, dest.*/, symbol->located_var_spec_init /*with*/);
773303b7f31f Remove potential access to NULL pointer.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   836
  }
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   837
  return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   838
}  
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   839
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   840
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   841
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   842
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   843
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
   844
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   845
/* 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
   846
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   847
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   848
/* 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
   849
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *fill_candidate_datatypes_c::visit(function_declaration_c *symbol) {
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   851
	if (debug) printf("Filling candidate data types list of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
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
   852
	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
   853
	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
   854
	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
   855
	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
   856
	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
   857
	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
   858
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   860
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   861
/* 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
   862
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   863
void *fill_candidate_datatypes_c::visit(function_block_declaration_c *symbol) {
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   864
	if (debug) printf("Filling candidate data types list of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
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
   865
	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
   866
	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
   867
	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
   868
	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
   869
	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
   870
	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
   871
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   872
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   873
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   874
/* 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
   875
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *fill_candidate_datatypes_c::visit(program_declaration_c *symbol) {
479
a174d61f2087 Re-organizing the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   877
	if (debug) printf("Filling candidate data types list in program %s\n", ((token_c *)(symbol->program_type_name))->value);
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
   878
	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
   879
	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
   880
	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
   881
	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
   882
	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
   883
	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
   884
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   885
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   886
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   887
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   888
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   889
/* 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
   890
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   891
void *fill_candidate_datatypes_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
   892
	// 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
   893
	/* 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
   894
	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
   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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   897
/****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   898
/* 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
   899
/****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   900
/***********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   901
/* 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
   902
/***********************************/
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: 442
diff changeset
   903
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: 442
diff changeset
   904
/*| instruction_list il_instruction */
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: 442
diff changeset
   905
// SYM_LIST(instruction_list_c)
464
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   906
void *fill_candidate_datatypes_c::visit(instruction_list_c *symbol) {
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   907
	/* In order to fill the data type candidates correctly
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
   908
	 * in IL instruction lists containing JMPs to labels that come before the JMP instruction
464
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   909
	 * itself, we need to run the fill candidate datatypes algorithm twice on the Instruction List.
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   910
	 * e.g.:  ...
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   911
	 *          ld 23
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   912
	 *   label1:st byte_var
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   913
	 *          ld 34
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   914
	 *          JMP label1     
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   915
	 *
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   916
	 * Note that the second time we run the algorithm, most of the candidate datatypes are already filled
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   917
	 * in, so it will be able to produce tha correct candidate datatypes for the IL instruction referenced
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   918
	 * by the label, as in the 2nd pass we already know the candidate datatypes of the JMP instruction!
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   919
	 */
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   920
	for(int j = 0; j < 2; j++) {
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   921
		for(int i = 0; i < symbol->n; i++) {
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   922
			symbol->elements[i]->accept(*this);
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   923
		}
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   924
	}
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   925
	return NULL;
319ee8b218f3 Handle JMP to labels preceding the JMP instruction itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 462
diff changeset
   926
}
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: 442
diff changeset
   927
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: 442
diff changeset
   928
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   929
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: 442
diff changeset
   930
/* | label ':' [il_incomplete_instruction] eol_list */
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: 442
diff changeset
   931
// SYM_REF2(il_instruction_c, label, il_instruction)
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: 442
diff changeset
   932
// void *visit(instruction_list_c *symbol);
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: 442
diff changeset
   933
void *fill_candidate_datatypes_c::visit(il_instruction_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: 447
diff changeset
   934
	if (NULL == symbol->il_instruction) {
450
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   935
		/* This empty/null il_instruction does not change the value of the current/default IL variable.
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   936
		 * So it inherits the candidate_datatypes from it's previous IL instructions!
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
   937
		 */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   938
		intersect_prev_candidate_datatype_lists(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: 447
diff changeset
   939
	} else {
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   940
		il_instruction_c fake_prev_il_instruction = *symbol;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   941
		intersect_prev_candidate_datatype_lists(&fake_prev_il_instruction);
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   942
457
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
   943
		if (symbol->prev_il_instruction.size() == 0)  prev_il_instruction = NULL;
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   944
		else                                          prev_il_instruction = &fake_prev_il_instruction;
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: 447
diff changeset
   945
		symbol->il_instruction->accept(*this);
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: 447
diff changeset
   946
		prev_il_instruction = NULL;
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: 447
diff changeset
   947
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: 447
diff changeset
   948
		/* This object has (inherits) the same candidate datatypes as the il_instruction */
467
4910eaa1206a Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents: 465
diff changeset
   949
		symbol->candidate_datatypes = symbol->il_instruction->candidate_datatypes;
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: 447
diff changeset
   950
	}
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: 442
diff changeset
   951
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: 442
diff changeset
   952
	return NULL;
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: 442
diff changeset
   953
}
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: 442
diff changeset
   954
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: 442
diff changeset
   955
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: 442
diff changeset
   956
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
   957
void *fill_candidate_datatypes_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
   958
	/* determine the data type of the 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
   959
	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
   960
		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
   961
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	/* recursive call to fill the candidate data types 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
   963
	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
   964
	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
   965
	il_operand = NULL;
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: 442
diff changeset
   966
	/* This object has (inherits) the same candidate datatypes as the il_simple_operator */
467
4910eaa1206a Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents: 465
diff changeset
   967
	symbol->candidate_datatypes = symbol->il_simple_operator->candidate_datatypes;
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
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   971
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   972
/* | function_name [il_operand_list] */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   973
/* 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: 437
diff changeset
   974
// 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
   975
void *fill_candidate_datatypes_c::visit(il_function_call_c *symbol) {
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   976
	/* The first parameter of a non formal function call in IL will be the 'current value' (i.e. the prev_il_instruction)
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   977
	 * In order to be able to handle this without coding special cases, we will simply prepend that symbol
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   978
	 * to the il_operand_list, and remove it after calling handle_function_call().
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   979
	 *
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   980
	 * However, if no further paramters are given, then il_operand_list will be NULL, and we will
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   981
	 * need to create a new object to hold the pointer to prev_il_instruction.
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   982
	 */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   983
	if (NULL == symbol->il_operand_list)  symbol->il_operand_list = new il_operand_list_c;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   984
	if (NULL == symbol->il_operand_list)  ERROR;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   985
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   986
	symbol->il_operand_list->accept(*this);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
   987
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   988
	if (NULL != prev_il_instruction) {
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   989
		((list_c *)symbol->il_operand_list)->insert_element(prev_il_instruction, 0);	
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   990
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   991
		generic_function_call_t fcall_param = {
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   992
			/* fcall_param.function_name               = */ symbol->function_name,
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   993
			/* fcall_param.nonformal_operand_list      = */ symbol->il_operand_list,
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   994
			/* fcall_param.formal_operand_list         = */ NULL,
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   995
			/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_function,
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   996
			/* fcall_param.candidate_functions         = */ symbol->candidate_functions,
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   997
			/* fcall_param.called_function_declaration = */ symbol->called_function_declaration,
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   998
			/* fcall_param.extensible_param_count      = */ symbol->extensible_param_count
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   999
		};
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1000
		handle_function_call(symbol, fcall_param);
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1001
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1002
		/* Undo the changes to the abstract syntax tree we made above... */
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1003
		((list_c *)symbol->il_operand_list)->remove_element(0);
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1004
	}
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1005
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1006
	/* Undo the changes to the abstract syntax tree we made above... */
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1007
	if (((list_c *)symbol->il_operand_list)->n == 0) {
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1008
		/* if the list becomes empty, then that means that it did not exist before we made these changes, so we delete it! */
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1009
		delete 	symbol->il_operand_list;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1010
		symbol->il_operand_list = NULL;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1011
	}
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
  1012
	
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1013
	if (debug) std::cout << "il_function_call_c [" << symbol->candidate_datatypes.size() << "] result.\n";
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1014
	return NULL;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1015
}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1016
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1017
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
  1018
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_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
  1019
// SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_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
  1020
void *fill_candidate_datatypes_c::visit(il_expression_c *symbol) {
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1021
  symbol_c *prev_il_instruction_backup = prev_il_instruction;
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1022
  
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
  1023
  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
  1024
    symbol->il_operand->accept(*this);
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1025
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1026
  if(symbol->simple_instr_list != NULL)
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
  1027
    symbol->simple_instr_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
  1028
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1029
  /* Now check the if the data type semantics of operation are correct,  */
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1030
  il_operand = symbol->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
  1031
  prev_il_instruction = prev_il_instruction_backup;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
  symbol->il_expr_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
  1033
  il_operand = NULL;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1034
  
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1035
  /* This object has the same candidate datatypes as the il_expr_operator. */
467
4910eaa1206a Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents: 465
diff changeset
  1036
  symbol->candidate_datatypes = symbol->il_expr_operator->candidate_datatypes;
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
  1037
  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
  1038
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1039
462
f7dada0a8952 Fix filling candidate datatypes of JMP operations
Mario de Sousa <msousa@fe.up.pt>
parents: 459
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
void *fill_candidate_datatypes_c::visit(il_jump_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
  1042
  /* recursive call to fill the candidate data types 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
  1043
  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
  1044
  symbol->il_jump_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
  1045
  il_operand = NULL;
462
f7dada0a8952 Fix filling candidate datatypes of JMP operations
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
  1046
  /* This object has the same candidate datatypes as the il_jump_operator. */
467
4910eaa1206a Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents: 465
diff changeset
  1047
  symbol->candidate_datatypes = symbol->il_jump_operator->candidate_datatypes;
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
  1048
  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
  1049
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1050
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
  1051
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
  1052
/*   il_call_operator prev_declared_fb_name
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
  1053
 * | il_call_operator prev_declared_fb_name '(' ')'
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
  1054
 * | il_call_operator prev_declared_fb_name '(' eol_list ')'
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
  1055
 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
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
  1056
 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
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
  1057
 */
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
  1058
/* 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 */
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
  1059
// 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
  1060
void *fill_candidate_datatypes_c::visit(il_fb_call_c *symbol) {
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1061
	/* We do not call
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1062
	 * fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1063
	 * because we want to make sure it is a FB instance, and not some other data type...
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1064
	 */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1065
	symbol_c *fb_type_id = search_varfb_instance_type->get_basetype_id(symbol->fb_name);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1066
	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1067
	if (NULL == fb_type_id) ERROR;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1068
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1069
 	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1070
	if (function_block_type_symtable.end_value() == fb_decl) 
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1071
		/* The fb_name not the name of a FB instance. Most probably it is the name of a variable of some other type. */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1072
		fb_decl = NULL;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1073
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
  1074
	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
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
  1075
	if (NULL == fb_decl) ERROR;
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
  1076
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1077
	if (symbol->  il_param_list != NULL) symbol->il_param_list->accept(*this);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1078
	if (symbol->il_operand_list != NULL) symbol->il_operand_list->accept(*this);
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
  1079
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
  1080
	/* The print_datatypes_error_c does not rely on this called_fb_declaration pointer being != NULL to conclude that
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
  1081
	 * we have a datat type incompatibility error, so setting it to the correct fb_decl is actually safe,
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
  1082
	 * as the compiler will never reach the compilation stage!
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
  1083
	 */
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
  1084
	symbol->called_fb_declaration = fb_decl;
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
  1085
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1086
	/* Let the il_call_operator (CAL, CALC, or CALCN) determine the candidate datatypes of the il_fb_call_c... */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1087
	/* NOTE: We ignore whether the call is 'compatible' or not when filling in the candidate datatypes list.
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1088
	 *       Even if it is not compatible, we fill in the candidate datatypes list correctly so that the following
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1089
	 *       IL instructions may be handled correctly and debuged.
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1090
	 *       Doing this is actually safe, as the parameter_list will still contain errors that will be found by
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1091
	 *       print_datatypes_error_c, so the code will never reach stage 4!
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1092
	 */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1093
	symbol->il_call_operator->accept(*this);
467
4910eaa1206a Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents: 465
diff changeset
  1094
	symbol->candidate_datatypes = symbol->il_call_operator->candidate_datatypes;
450
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 449
diff changeset
  1095
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
  1096
	if (debug) std::cout << "FB [] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
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
  1097
	return NULL;
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
  1098
}
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
  1099
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
  1100
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1101
/* | 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: 437
diff changeset
  1102
/* 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: 437
diff changeset
  1103
// 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
  1104
void *fill_candidate_datatypes_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: 437
diff changeset
  1105
	symbol->il_param_list->accept(*this);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1106
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1107
	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: 440
diff changeset
  1108
		/* 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: 440
diff changeset
  1109
		/* 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: 440
diff changeset
  1110
		/* 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: 440
diff changeset
  1111
		/* 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: 440
diff changeset
  1112
		/* 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: 440
diff changeset
  1113
		/* 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: 440
diff changeset
  1114
		/* 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: 437
diff changeset
  1115
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1116
	handle_function_call(symbol, fcall_param);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1117
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1118
	if (debug) std::cout << "il_formal_funct_call_c [" << symbol->candidate_datatypes.size() << "] result.\n";
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1119
	return NULL;
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1120
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1121
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1122
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1123
//     void *visit(il_operand_list_c *symbol);
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1124
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1125
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1126
/* | simple_instr_list il_simple_instruction */
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1127
/* This object is referenced by il_expression_c objects */
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1128
void *fill_candidate_datatypes_c::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: 452
diff changeset
  1129
  if (symbol->n <= 0)
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1130
    return NULL;  /* List is empty! Nothing to do. */
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1131
    
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1132
  for(int i = 0; i < symbol->n; i++)
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1133
    symbol->elements[i]->accept(*this);
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1134
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1135
  /* This object has (inherits) the same candidate datatypes as the last il_instruction */
467
4910eaa1206a Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents: 465
diff changeset
  1136
  symbol->candidate_datatypes = symbol->elements[symbol->n-1]->candidate_datatypes;
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1137
  
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1138
  if (debug) std::cout << "simple_instr_list_c [" << symbol->candidate_datatypes.size() << "] result.\n";
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1139
  return NULL;
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1140
}
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1141
457
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
  1142
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
  1143
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
  1144
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1145
// SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1146
void *fill_candidate_datatypes_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: 457
diff changeset
  1147
  if (symbol->prev_il_instruction.size() > 1) ERROR; /* There should be no labeled insructions inside an IL expression! */
457
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
  1148
  if (symbol->prev_il_instruction.size() == 0)  prev_il_instruction = NULL;
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
  1149
  else                                          prev_il_instruction = symbol->prev_il_instruction[0];
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1150
  symbol->il_simple_instruction->accept(*this);
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1151
  prev_il_instruction = NULL;
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1152
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1153
  /* This object has (inherits) the same candidate datatypes as the il_simple_instruction it points to */
467
4910eaa1206a Delete no longer needed copy_candidate_datatype_list() function.
Mario de Sousa <msousa@fe.up.pt>
parents: 465
diff changeset
  1154
  symbol->candidate_datatypes = symbol->il_simple_instruction->candidate_datatypes;
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1155
  return NULL;
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1156
}
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1157
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1158
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
  1159
/*
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1160
    void *visit(il_param_list_c *symbol);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1161
    void *visit(il_param_assignment_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
  1162
    void *visit(il_param_out_assignment_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
  1163
*/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1164
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1165
/*******************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1166
/* 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
  1167
/*******************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1168
void *fill_candidate_datatypes_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
  1169
	for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) {
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1170
		add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
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
  1171
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1172
	if (debug) std::cout << "LD [" <<  il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1173
	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
  1174
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1175
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1176
void *fill_candidate_datatypes_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
  1177
	for(unsigned int i = 0; i < il_operand->candidate_datatypes.size(); i++) {
666
8ba9ec4bae50 Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
  1178
		if      (get_datatype_info_c::is_ANY_BIT_compatible(il_operand->candidate_datatypes[i]))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1179
			add_datatype_to_candidate_list(symbol, il_operand->candidate_datatypes[i]);
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
  1180
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1181
	if (debug) std::cout << "LDN [" << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1182
	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
  1183
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1184
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1185
void *fill_candidate_datatypes_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
  1186
	symbol_c *prev_instruction_type, *operand_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
  1187
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	if (NULL == prev_il_instruction) 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
  1189
	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			operand_type = il_operand->candidate_datatypes[j];
440
a745f7d38a5d Fix typo error in some il visit in fill_candidate_datatypes_c class.
Manuele Conti <conti.ma@alice.it>
parents: 439
diff changeset
  1193
			if (is_type_equal(prev_instruction_type, operand_type))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1194
				add_datatype_to_candidate_list(symbol, prev_instruction_type);
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
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	if (debug) std::cout << "ST [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
  1199
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1200
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1201
void *fill_candidate_datatypes_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
  1202
	symbol_c *prev_instruction_type, *operand_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
  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
	if (NULL == prev_il_instruction) 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
  1205
	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			operand_type = il_operand->candidate_datatypes[j];
666
8ba9ec4bae50 Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
  1209
			if (is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_ANY_BIT_compatible(operand_type))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1210
				add_datatype_to_candidate_list(symbol, prev_instruction_type);
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
  1211
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	if (debug) std::cout << "STN [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1214
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1215
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1216
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1217
void *fill_candidate_datatypes_c::visit(NOT_operator_c *symbol) {
470
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 467
diff changeset
  1218
	/* 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: 467
diff changeset
  1219
	 *              NOT [<il_operand>]
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 467
diff changeset
  1220
	 *       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: 467
diff changeset
  1221
	 *       We therefore consider it an error if an il_operand is specified!
612
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 610
diff changeset
  1222
	 *       We do not need to generate an error message. This error will be caught somewhere else!
470
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 467
diff changeset
  1223
	 */
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 467
diff changeset
  1224
	if (NULL == prev_il_instruction) return NULL;
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 467
diff changeset
  1225
	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
666
8ba9ec4bae50 Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
  1226
		if (get_datatype_info_c::is_ANY_BIT_compatible(prev_il_instruction->candidate_datatypes[i]))
470
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 467
diff changeset
  1227
			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 467
diff changeset
  1228
	}
d2cd05c5e01a Semantic verification of NOT operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 467
diff changeset
  1229
	if (debug) std::cout <<  "NOT_operator [" << prev_il_instruction->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
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
  1230
	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
  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
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
  1233
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1234
void *fill_candidate_datatypes_c::visit(S_operator_c *symbol) {
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
  1235
  /* 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
  1236
	symbol_c *prev_instruction_type, *operand_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
  1237
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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 == prev_il_instruction) return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1239
	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1240
		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			operand_type = il_operand->candidate_datatypes[j];
473
933d6c204607 Add a TODO comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1243
			/* TODO: I believe the following is wrong! The data types of prev_instruction_type and operand_type DO NOT have to be equal.
933d6c204607 Add a TODO comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1244
			 * the prev_instruction_type MUST be BOOL compatible.
933d6c204607 Add a TODO comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1245
			 * I am not too sure about operand_type, does it have to be BOOL compatible, or can it be ANY_BIT compatible? Must check!
933d6c204607 Add a TODO comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1246
			 */
666
8ba9ec4bae50 Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
  1247
			if (is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_BOOL_compatible(operand_type))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1248
				add_datatype_to_candidate_list(symbol, prev_instruction_type);
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
  1249
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1250
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	if (debug) std::cout << "S [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	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
  1253
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1254
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
  1255
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
  1256
void *fill_candidate_datatypes_c::visit(R_operator_c *symbol) {
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
  1257
  /* 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
  1258
	symbol_c *prev_instruction_type, *operand_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
  1259
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	if (NULL == prev_il_instruction) 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
  1261
	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
		for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			prev_instruction_type = prev_il_instruction->candidate_datatypes[i];
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
			operand_type = il_operand->candidate_datatypes[j];
473
933d6c204607 Add a TODO comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1265
			/* TODO: I believe the following is wrong! The data types of prev_instruction_type and operand_type DO NOT have to be equal.
933d6c204607 Add a TODO comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1266
			 * the prev_instruction_type MUST be BOOL compatible.
933d6c204607 Add a TODO comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1267
			 * I am not too sure about operand_type, does it have to be BOOL compatible, or can it be ANY_BIT compatible? Must check!
933d6c204607 Add a TODO comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1268
			 */
666
8ba9ec4bae50 Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
  1269
			if (is_type_equal(prev_instruction_type,operand_type) && get_datatype_info_c::is_BOOL_compatible(operand_type))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1270
				add_datatype_to_candidate_list(symbol, prev_instruction_type);
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
  1271
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
	if (debug) std::cout << "R [" << prev_il_instruction->candidate_datatypes.size() << "," << il_operand->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1274
	return NULL;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1275
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1276
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
  1277
489
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1278
void *fill_candidate_datatypes_c::visit( S1_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "S1", symbol->called_fb_declaration);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1279
void *fill_candidate_datatypes_c::visit( R1_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "R1", symbol->called_fb_declaration);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1280
void *fill_candidate_datatypes_c::visit( CLK_operator_c *symbol) {return handle_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1281
void *fill_candidate_datatypes_c::visit( CU_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "CU", symbol->called_fb_declaration);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1282
void *fill_candidate_datatypes_c::visit( CD_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "CD", symbol->called_fb_declaration);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1283
void *fill_candidate_datatypes_c::visit( PV_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "PV", symbol->called_fb_declaration);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1284
void *fill_candidate_datatypes_c::visit( IN_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "IN", symbol->called_fb_declaration);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1285
void *fill_candidate_datatypes_c::visit( PT_operator_c  *symbol) {return handle_implicit_il_fb_call(symbol,  "PT", symbol->called_fb_declaration);}
447
aad0f3e5df33 Start of support for semantic verification of FB calls in IL using special IL instructions.
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
  1286
483
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 481
diff changeset
  1287
void *fill_candidate_datatypes_c::visit( AND_operator_c *symbol) {return handle_binary_operator(widen_AND_table, symbol, prev_il_instruction, il_operand);}
489
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1288
void *fill_candidate_datatypes_c::visit(  OR_operator_c *symbol) {return handle_binary_operator( widen_OR_table, symbol, prev_il_instruction, il_operand);}
483
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 481
diff changeset
  1289
void *fill_candidate_datatypes_c::visit( XOR_operator_c *symbol) {return handle_binary_operator(widen_XOR_table, symbol, prev_il_instruction, il_operand);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 481
diff changeset
  1290
void *fill_candidate_datatypes_c::visit(ANDN_operator_c *symbol) {return handle_binary_operator(widen_AND_table, symbol, prev_il_instruction, il_operand);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 481
diff changeset
  1291
void *fill_candidate_datatypes_c::visit( ORN_operator_c *symbol) {return handle_binary_operator( widen_OR_table, symbol, prev_il_instruction, il_operand);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 481
diff changeset
  1292
void *fill_candidate_datatypes_c::visit(XORN_operator_c *symbol) {return handle_binary_operator(widen_XOR_table, symbol, prev_il_instruction, il_operand);}
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
  1293
489
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1294
void *fill_candidate_datatypes_c::visit( ADD_operator_c *symbol) {return handle_binary_operator(widen_ADD_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1295
void *fill_candidate_datatypes_c::visit( SUB_operator_c *symbol) {return handle_binary_operator(widen_SUB_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1296
void *fill_candidate_datatypes_c::visit( MUL_operator_c *symbol) {return handle_binary_operator(widen_MUL_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1297
void *fill_candidate_datatypes_c::visit( DIV_operator_c *symbol) {return handle_binary_operator(widen_DIV_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1298
void *fill_candidate_datatypes_c::visit( MOD_operator_c *symbol) {return handle_binary_operator(widen_MOD_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1299
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1300
void *fill_candidate_datatypes_c::visit(  GT_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1301
void *fill_candidate_datatypes_c::visit(  GE_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1302
void *fill_candidate_datatypes_c::visit(  EQ_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1303
void *fill_candidate_datatypes_c::visit(  LT_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1304
void *fill_candidate_datatypes_c::visit(  LE_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1305
void *fill_candidate_datatypes_c::visit(  NE_operator_c *symbol) {return handle_binary_operator(widen_CMP_table, symbol, prev_il_instruction, il_operand);}
484
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1306
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1307
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
  1308
487
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1309
void *fill_candidate_datatypes_c::handle_conditional_il_flow_control_operator(symbol_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
  1310
	if (NULL == prev_il_instruction) 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
  1311
	for (unsigned int i = 0; i < prev_il_instruction->candidate_datatypes.size(); i++) {
666
8ba9ec4bae50 Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
  1312
		if (get_datatype_info_c::is_BOOL_compatible(prev_il_instruction->candidate_datatypes[i]))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1313
			add_datatype_to_candidate_list(symbol, prev_il_instruction->candidate_datatypes[i]);
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
  1314
	}
487
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1315
	return NULL;
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1316
}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1317
489
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1318
void *fill_candidate_datatypes_c::visit(  CAL_operator_c *symbol) {if (NULL != prev_il_instruction) symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1319
void *fill_candidate_datatypes_c::visit(  RET_operator_c *symbol) {if (NULL != prev_il_instruction) symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;}
2c874cccbb44 Some stupid code cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 488
diff changeset
  1320
void *fill_candidate_datatypes_c::visit(  JMP_operator_c *symbol) {if (NULL != prev_il_instruction) symbol->candidate_datatypes = prev_il_instruction->candidate_datatypes; return NULL;}
487
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1321
void *fill_candidate_datatypes_c::visit( CALC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1322
void *fill_candidate_datatypes_c::visit(CALCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1323
void *fill_candidate_datatypes_c::visit( RETC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1324
void *fill_candidate_datatypes_c::visit(RETCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1325
void *fill_candidate_datatypes_c::visit( JMPC_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1326
void *fill_candidate_datatypes_c::visit(JMPCN_operator_c *symbol) {return handle_conditional_il_flow_control_operator(symbol);}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1327
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1328
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1329
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1330
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
  1331
/* 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
  1332
// 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
  1333
/* 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
  1334
// 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
  1335
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1336
/***************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1337
/* 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
  1338
/***************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1339
/***********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1340
/* 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
  1341
/***********************/
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1342
void *fill_candidate_datatypes_c::visit(   or_expression_c  *symbol) {return handle_binary_expression  (widen_OR_table,  symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1343
void *fill_candidate_datatypes_c::visit(   xor_expression_c *symbol) {return handle_binary_expression  (widen_XOR_table, symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1344
void *fill_candidate_datatypes_c::visit(   and_expression_c *symbol) {return handle_binary_expression  (widen_AND_table, symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1345
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1346
void *fill_candidate_datatypes_c::visit(   equ_expression_c *symbol) {return handle_equality_comparison(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1347
void *fill_candidate_datatypes_c::visit(notequ_expression_c *symbol) {return handle_equality_comparison(widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1348
void *fill_candidate_datatypes_c::visit(    lt_expression_c *symbol) {return handle_binary_expression  (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1349
void *fill_candidate_datatypes_c::visit(    gt_expression_c *symbol) {return handle_binary_expression  (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1350
void *fill_candidate_datatypes_c::visit(    le_expression_c *symbol) {return handle_binary_expression  (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1351
void *fill_candidate_datatypes_c::visit(    ge_expression_c *symbol) {return handle_binary_expression  (widen_CMP_table, symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1352
 
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1353
void *fill_candidate_datatypes_c::visit(   add_expression_c *symbol) {return handle_binary_expression  (widen_ADD_table,  symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1354
void *fill_candidate_datatypes_c::visit(   sub_expression_c *symbol) {return handle_binary_expression  (widen_SUB_table,  symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1355
void *fill_candidate_datatypes_c::visit(   mul_expression_c *symbol) {return handle_binary_expression  (widen_MUL_table,  symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1356
void *fill_candidate_datatypes_c::visit(   div_expression_c *symbol) {return handle_binary_expression  (widen_DIV_table,  symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1357
void *fill_candidate_datatypes_c::visit(   mod_expression_c *symbol) {return handle_binary_expression  (widen_MOD_table,  symbol, symbol->l_exp, symbol->r_exp);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 651
diff changeset
  1358
void *fill_candidate_datatypes_c::visit( power_expression_c *symbol) {return handle_binary_expression  (widen_EXPT_table, 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
  1359
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1360
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1361
void *fill_candidate_datatypes_c::visit(neg_expression_c *symbol) {
435
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1362
  /* NOTE: The standard defines the syntax for this 'negation' operation, but
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1363
   *       does not define the its semantics.
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1364
   *
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1365
   *       We could be tempted to consider that the semantics of the
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1366
   *       'negation' operation are similar/identical to the semantics of the 
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1367
   *       SUB expression/operation. This would include assuming that the
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1368
   *       possible datatypes for the 'negation' operation is also
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1369
   *       the same as those for the SUB expression/operation, namely ANY_MAGNITUDE.
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1370
   *
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1371
   *       However, this would then mean that the following ST code would be 
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1372
   *       syntactically and semantically correct:
650
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1373
   *       VAR uint_var : UINT END_VAR;
435
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1374
   *       uint_var := - (uint_var);
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1375
   *
650
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1376
   *       Assuming uint_var is not 0, the standard states that the above code should result in a 
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1377
   *       runtime error since the operation will result in an overflow. Since the above operation
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1378
   *       is only valid when uint_var=0, it would probably make more sense for the programmer to
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1379
   *       use if (uint_var=0) ..., so we will simply assume that the above statement simply
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1380
   *       does not make sense in any situation (whether or not uint_var is 0), and therefore
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1381
   *       we will not allow it.
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1382
   *       (Notice that doing so does not ago against the standard, as the standard does not
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1383
   *       explicitly define the semantics of the NEG operator, nor the data types it may accept
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1384
   *       as input. We are simply assuming that the NEG operator may not be applied to unsigned
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1385
   *       ANY_NUM data types!).
435
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1386
   *
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1387
   *       It is much easier for the compiler to detect this at compile time,
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1388
   *       and it is probably safer to the resulting code too.
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1389
   *
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1390
   *       To detect these tyes of errors at compile time, the easisest solution
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1391
   *       is to only allow ANY_NUM datatytpes that are signed.
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1392
   *        So, that is what we do here!
650
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1393
   *
d39eed7cc2af Add some comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 643
diff changeset
  1394
   * NOTE: The above argument also applies to the neg_integer_c method!
435
82cb6a64a763 Change negation expression (neg_expression_c) to only allow signed data types.
Mario de Sousa <msousa@fe.up.pt>
parents: 431
diff changeset
  1395
   */
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
  1396
	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
  1397
	for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) {
666
8ba9ec4bae50 Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
  1398
		if (get_datatype_info_c::is_ANY_signed_MAGNITUDE_compatible(symbol->exp->candidate_datatypes[i]))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1399
			add_datatype_to_candidate_list(symbol, symbol->exp->candidate_datatypes[i]);
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
  1400
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1401
	if (debug) std::cout << "neg [" << symbol->exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1402
	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
  1403
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1404
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1405
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1406
void *fill_candidate_datatypes_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
  1407
	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
  1408
	for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) {
666
8ba9ec4bae50 Add new get_datatype_info_c (preparing to remove search_expression_type_c)
Mario de Sousa <msousa@fe.up.pt>
parents: 661
diff changeset
  1409
		if      (get_datatype_info_c::is_ANY_BIT_compatible(symbol->exp->candidate_datatypes[i]))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1410
			add_datatype_to_candidate_list(symbol, symbol->exp->candidate_datatypes[i]);
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
  1411
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1412
	if (debug) std::cout << "not [" << symbol->exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1413
	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
  1414
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1415
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1416
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1417
void *fill_candidate_datatypes_c::visit(function_invocation_c *symbol) {
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1418
	if      (NULL != symbol->formal_param_list)        symbol->   formal_param_list->accept(*this);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1419
	else if (NULL != symbol->nonformal_param_list)     symbol->nonformal_param_list->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1420
	else ERROR;
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1421
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1422
	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: 440
diff changeset
  1423
		/* 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: 440
diff changeset
  1424
		/* 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: 440
diff changeset
  1425
		/* 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: 440
diff changeset
  1426
		/* 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: 440
diff changeset
  1427
		/* 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: 440
diff changeset
  1428
		/* 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: 440
diff changeset
  1429
		/* 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: 437
diff changeset
  1430
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1431
	handle_function_call(symbol, fcall_param);
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1432
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 437
diff changeset
  1433
	if (debug) std::cout << "function_invocation_c [" << symbol->candidate_datatypes.size() << "] result.\n";
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
  1434
	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
  1435
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1436
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
  1437
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 420
diff changeset
  1438
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
  1439
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1440
/* 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
  1441
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1442
// SYM_LIST(statement_list_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
  1443
/* The visitor of the base class search_visitor_c will handle calling each instruction in the 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
  1444
 * We do not need to do anything here...
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1445
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1446
// void *fill_candidate_datatypes_c::visit(statement_list_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
  1447
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1448
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1449
/*********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1450
/* 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
  1451
/*********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1452
void *fill_candidate_datatypes_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
  1453
	symbol_c *left_type, *right_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
  1454
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1455
	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
  1456
	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
  1457
	for (unsigned int i = 0; i < symbol->l_exp->candidate_datatypes.size(); i++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1458
		for(unsigned int j = 0; j < symbol->r_exp->candidate_datatypes.size(); j++) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1459
			left_type = symbol->l_exp->candidate_datatypes[i];
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1460
			right_type = symbol->r_exp->candidate_datatypes[j];
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1461
			if (is_type_equal(left_type, right_type))
465
b52ec62773db Do not allow duplicate values in candidate datatype list.
Mario de Sousa <msousa@fe.up.pt>
parents: 464
diff changeset
  1462
				add_datatype_to_candidate_list(symbol, left_type);
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
  1463
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1464
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1465
	if (debug) std::cout << ":= [" << symbol->l_exp->candidate_datatypes.size() << "," << symbol->r_exp->candidate_datatypes.size() << "] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1466
	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
  1467
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1468
418
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1469
/*****************************************/
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1470
/* B 3.2.2 Subprogram Control Statements */
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1471
/*****************************************/
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1472
void *fill_candidate_datatypes_c::visit(fb_invocation_c *symbol) {
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1473
	symbol_c *fb_type_id = search_varfb_instance_type->get_basetype_id(symbol->fb_name);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1474
	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1475
	if (NULL == fb_type_id) ERROR;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1476
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1477
	function_block_declaration_c *fb_decl = function_block_type_symtable.find_value(fb_type_id);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1478
	if (function_block_type_symtable.end_value() == fb_decl) 
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1479
		/* The fb_name not the name of a FB instance. Most probably it is the name of a variable of some other type. */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1480
		fb_decl = NULL;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1481
424
43d73e28eca8 Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents: 422
diff changeset
  1482
	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
418
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1483
	if (NULL == fb_decl) ERROR;
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1484
	
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1485
	if (symbol->   formal_param_list != NULL) symbol->formal_param_list->accept(*this);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1486
	if (symbol->nonformal_param_list != NULL) symbol->nonformal_param_list->accept(*this);
424
43d73e28eca8 Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents: 422
diff changeset
  1487
431
5792016eedd8 More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 429
diff changeset
  1488
	/* The print_datatypes_error_c does not rely on this called_fb_declaration pointer being != NULL to conclude that
5792016eedd8 More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 429
diff changeset
  1489
	 * we have a datat type incompatibility error, so setting it to the correct fb_decl is actually safe,
5792016eedd8 More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 429
diff changeset
  1490
	 * as the compiler will never reach the compilation stage!
5792016eedd8 More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 429
diff changeset
  1491
	 */
5792016eedd8 More detailed error messages for FB invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 429
diff changeset
  1492
	symbol->called_fb_declaration = fb_decl;
424
43d73e28eca8 Continue checking data type compatibility inside expressions used to pass paramters to invalid function/FB calls
Mario de Sousa <msousa@fe.up.pt>
parents: 422
diff changeset
  1493
418
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1494
	if (debug) std::cout << "FB [] ==> "  << symbol->candidate_datatypes.size() << " result.\n";
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1495
	return NULL;
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1496
}
2ac41d2cba91 Add fill candidate method for fb_invocation_c symbol.
Manuele Conti <conti.ma@alice.it>
parents: 417
diff changeset
  1497
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
  1498
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1499
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1500
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1501
/* 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
  1502
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1503
void *fill_candidate_datatypes_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
  1504
	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
  1505
	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
  1506
		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
  1507
	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
  1508
		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
  1509
	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
  1510
		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
  1511
	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
  1512
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1513
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1514
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1515
void *fill_candidate_datatypes_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
  1516
	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
  1517
	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
  1518
		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
  1519
	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
  1520
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1521
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1522
/* CASE expression OF case_element_list ELSE statement_list END_CASE */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1523
// SYM_REF3(case_statement_c, expression, case_element_list, 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
  1524
void *fill_candidate_datatypes_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
  1525
	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
  1526
	if (NULL != symbol->case_element_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
  1527
		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
  1528
	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
  1529
		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
  1530
	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
  1531
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1532
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1533
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1534
/* helper symbol for case_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
  1535
// SYM_LIST(case_element_list_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
  1536
/* NOTE: visitor method for case_element_list_c is not required since we inherit from iterator_visitor_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
  1537
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1538
/*  case_list ':' 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
  1539
// SYM_REF2(case_element_c, case_list, 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
  1540
/* NOTE: visitor method for case_element_c is not required since we inherit from iterator_visitor_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
  1541
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1542
// SYM_LIST(case_list_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
  1543
/* NOTE: visitor method for case_list_c is not required since we inherit from iterator_visitor_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
  1544
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1545
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1546
/* 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
  1547
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1548
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1549
void *fill_candidate_datatypes_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
  1550
	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
  1551
	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
  1552
	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
  1553
	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
  1554
		symbol->by_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
  1555
	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
  1556
		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
  1557
	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
  1558
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1559
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1560
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1561
void *fill_candidate_datatypes_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
  1562
	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
  1563
	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
  1564
		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
  1565
	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
  1566
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1567
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1568
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1569
void *fill_candidate_datatypes_c::visit(repeat_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
  1570
	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
  1571
	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
  1572
		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
  1573
	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
  1574
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1575
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1576
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1577
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1578
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1579
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1580