stage3/narrow_candidate_datatypes.cc
author mjsousa
Thu, 31 Jul 2014 17:49:44 +0100
changeset 919 8da635655f37
parent 910 a0518971127d
child 933 76324f461aed
permissions -rwxr-xr-x
Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
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
552
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    35
/* NOTE: The algorithm implemented here assumes that candidate datatype lists have already been filled!
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    36
 *       BEFORE running this visitor, be sure to CALL the fill_candidate_datatype_c visitor!
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    37
 */
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    38
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    39
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
    40
/*
552
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    41
 *  Choose, from the list of all the possible datatypes each expression may take, the single datatype that it will in fact take.
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    42
 *  The resulting (chosen) datatype, will be stored in the symbol_c.datatype variable, leaving the candidate datatype list untouched!
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    43
 * 
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    44
 *  For rvalue expressions, this decision will be based on the datatype of the lvalue expression.
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    45
 *  For lvalue expressions, the candidate datatype list should have a single entry.
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    46
 * 
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    47
 *  For example, the very simple literal '0' in 'foo := 0', may represent a:
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    48
 *    BOOL, BYTE, WORD, DWORD, LWORD, USINT, SINT, UINT, INT, UDINT, DINT, ULINT, LINT (as well as the SAFE versions of these data tyes too!)
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    49
 * 
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    50
 *  In this class, the datatype of '0' will be set to the same datatype as the 'foo' variable.
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    51
 *  If the intersection of the candidate datatype lists of the left and right side expressions is empty, 
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    52
 *  then a datatype error has been found, and the datatype is either left at NULL, or set to a pointer of an invalid_type_name_c object!
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
    53
 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    54
552
3c39d80fdede Add high level comments.
mjsousa <msousa@fe.up.pt>
parents: 534
diff changeset
    55
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
#include "narrow_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
    57
#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
    58
#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
    59
#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
    60
#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
    61
#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
    62
#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
    63
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* set to 1 to see debug info during execution */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    66
static int debug = 0;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    67
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    68
narrow_candidate_datatypes_c::narrow_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
    69
	search_varfb_instance_type = NULL;
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 652
diff changeset
    70
	fake_prev_il_instruction = NULL;
674
b221168a36f1 Set datatype of il_intruction_c objects containing an ST operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 673
diff changeset
    71
	current_il_instruction   = NULL;
661
f537c3315f83 Minor changes needed to build with pedantic flag.
Manuele Conti <conti.ma@alice.it>
parents: 652
diff changeset
    72
	il_operand = NULL;
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
    73
	current_scope = 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
    74
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    75
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    76
narrow_candidate_datatypes_c::~narrow_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
    77
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
    79
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
    80
/* Only set the symbol's desired datatype to 'datatype' if that datatype is in the candidate_datatype list */
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
    81
static void set_datatype(symbol_c *datatype, symbol_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
    82
  
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    83
	/* If we are trying to set to the undefined type, and the symbol's datatype has already been set to something else, 
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    84
	 * we abort the compoiler as I don't think this should ever occur. 
466
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
    85
	 * NOTE: In order to handle JMPs to labels that come before the JMP itself, we run the narrow algorithm twice.
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
    86
	 *       This means that this situation may legally occur, so we cannot abort the compiler here!
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
    87
	 */
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
    88
// 	if ((NULL == datatype) && (NULL != symbol->datatype)) ERROR;
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
    89
 	if ((NULL == datatype) && (NULL != symbol->datatype)) return;
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    90
	if ((NULL == datatype) && (NULL == symbol->datatype)) return;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    91
	
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    92
	if (search_in_candidate_datatype_list(datatype, symbol->candidate_datatypes) < 0)
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
    93
		symbol->datatype = &(get_datatype_info_c::invalid_type_name);   
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    94
	else {
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    95
		if (NULL == symbol->datatype)   
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    96
			/* not yet set to anything, so we set it to the requested data type */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    97
			symbol->datatype = datatype; 
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    98
		else {
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
    99
			/* had already been set previously to some data type. Let's check if they are the same! */
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 675
diff changeset
   100
			if (!get_datatype_info_c::is_type_equal(symbol->datatype, datatype))
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
   101
				symbol->datatype = &(get_datatype_info_c::invalid_type_name);
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   102
// 			else 
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   103
				/* we leave it unchanged, as it is the same as the requested data type! */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   104
		}
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   105
	}
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   106
}
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   107
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   108
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   109
457
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
   110
/* Only set the symbol's desired datatype to 'datatype' if that datatype is in the candidate_datatype list */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   111
// static void set_datatype_in_prev_il_instructions(symbol_c *datatype, std::vector <symbol_c *> prev_il_instructions) {
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   112
static void set_datatype_in_prev_il_instructions(symbol_c *datatype, il_instruction_c *symbol) {
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   113
	if (NULL == symbol) ERROR;
457
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
   114
	for (unsigned int i = 0; i < symbol->prev_il_instruction.size(); i++)
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
   115
		set_datatype(datatype, symbol->prev_il_instruction[i]);
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
   116
}
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
   117
67d8b07bac22 Change prev_il_instruction to a vector<>
Mario de Sousa <msousa@fe.up.pt>
parents: 456
diff changeset
   118
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   119
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   120
bool narrow_candidate_datatypes_c::is_widening_compatible(const struct widen_entry widen_table[], symbol_c *left_type, symbol_c *right_type, symbol_c *result_type, bool *deprecated_status) {
515
fdef852a6565 Fix bug when handling code with data type errors.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   121
	/* NOTE: According to our algorithm, left_type and right_type should never by NULL (if they are, we have an internal compiler error!
fdef852a6565 Fix bug when handling code with data type errors.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   122
	 *       However, result_type may be NULL if the code has a data type semantic error!
fdef852a6565 Fix bug when handling code with data type errors.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   123
	 */
fdef852a6565 Fix bug when handling code with data type errors.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   124
	if ((NULL == left_type) || (NULL == right_type) || (NULL == result_type))
fdef852a6565 Fix bug when handling code with data type errors.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   125
		return false;
fdef852a6565 Fix bug when handling code with data type errors.
Mario de Sousa <msousa@fe.up.pt>
parents: 502
diff changeset
   126
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
   127
	for (int k = 0; NULL != widen_table[k].left;  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
   128
		if        ((typeid(*left_type)   == typeid(*widen_table[k].left))
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   129
		        && (typeid(*right_type)  == typeid(*widen_table[k].right))
478
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
   130
			&& (typeid(*result_type) == typeid(*widen_table[k].result))) {
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   131
			if (NULL != deprecated_status)
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
   132
				*deprecated_status = (widen_table[k].status == widen_entry::deprecated);
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
   133
			return true;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   134
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   135
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   136
	return false;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   137
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   138
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   139
/*
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   140
 * 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: 441
diff changeset
   141
 * 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: 441
diff changeset
   142
 * 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: 441
diff changeset
   143
 */
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   144
void narrow_candidate_datatypes_c::narrow_nonformal_call(symbol_c *f_call, symbol_c *f_decl, int *ext_parm_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
   145
	symbol_c *call_param_value,  *param_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
   146
	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
   147
	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
   148
	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
   149
	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
   150
	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
   151
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   152
	if (NULL != ext_parm_count) *ext_parm_count = -1;
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
   153
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   154
	/* 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
   155
	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
   156
		/* 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
   157
		/* 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
   158
		 * 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
   159
		 */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   160
		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
   161
			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
   162
			/* If there is no other parameter declared, then we are passing too many parameters... */
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: 423
diff changeset
   163
			/* This error should have been caught in fill_candidate_datatypes_c, but may occur here again when we handle FB invocations! 
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: 423
diff changeset
   164
			 * In this case, we carry on analysing the code in order to be able to provide relevant error messages
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: 423
diff changeset
   165
			 * for that code too!
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: 423
diff changeset
   166
			 */
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: 423
diff changeset
   167
			if(param_name == NULL) 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
   168
		} 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
   169
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   170
		/* Set the desired datatype for this parameter, and call it recursively. */
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: 423
diff changeset
   171
		/* Note that if the call has more parameters than those declared in the function/FB declaration,
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: 423
diff changeset
   172
		 * we may be setting this to NULL!
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: 423
diff changeset
   173
		 */
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   174
		symbol_c *desired_datatype = base_type(fp_iterator.param_type());
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   175
		if ((NULL != param_name) && (NULL == desired_datatype)) ERROR;
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   176
		if ((NULL == param_name) && (NULL != desired_datatype)) ERROR;
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   177
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   178
		/* NOTE: When we are handling a nonformal function call made from IL, the first parameter is the 'default' or 'current'
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   179
		 *       il value. However, a pointer to a copy of the prev_il_instruction is pre-pended into the operand list, so 
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   180
		 *       the 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: 441
diff changeset
   181
		 *       call_param_value->accept(*this);
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   182
		 *       may actually be calling an object of the base symbol_c .
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   183
		 */
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   184
		set_datatype(desired_datatype, call_param_value);
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   185
		call_param_value->accept(*this);
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   186
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: 423
diff changeset
   187
		if (NULL != param_name) 
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: 423
diff changeset
   188
			if (extensible_parameter_highest_index < fp_iterator.extensible_param_index())
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: 423
diff changeset
   189
				extensible_parameter_highest_index = fp_iterator.extensible_param_index();
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: 423
diff changeset
   190
	}
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   191
	/* In the case of a call to an extensible function, we store the highest index 
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   192
	 * of the extensible parameters this particular call uses, in the symbol_c object
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   193
	 * of the function call itself!
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   194
	 * In calls to non-extensible functions, this value will be set to -1.
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   195
	 * This information is later used in stage4 to correctly generate the
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   196
	 * output code.
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   197
	 */
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   198
	if ((NULL != ext_parm_count) && (extensible_parameter_highest_index >=0) /* if call to extensible function */)
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   199
		*ext_parm_count = 1 + extensible_parameter_highest_index - fp_iterator.first_extensible_param_index();
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   200
}
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   201
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   202
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   203
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   204
void narrow_candidate_datatypes_c::narrow_formal_call(symbol_c *f_call, symbol_c *f_decl, int *ext_parm_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
   205
	symbol_c *call_param_value, *call_param_name, *param_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
   206
	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
   207
	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
   208
	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
   209
	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
   210
	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
   211
	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
   212
	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
   213
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   214
	if (NULL != ext_parm_count) *ext_parm_count = -1;
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
	/* 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
   216
	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
   217
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   223
		/* 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
   224
		param_name = fp_iterator.search(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
   225
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   226
		/* Set the desired datatype for this parameter, and call it recursively. */
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: 423
diff changeset
   227
		/* NOTE: When handling a FB call, this narrow_formal_call() may be called to analyse
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: 423
diff changeset
   228
		 *       an invalid FB call (call with parameters that do not exist on the FB declaration).
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: 423
diff changeset
   229
		 *       For this reason, the param_name may come out as NULL!
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: 423
diff changeset
   230
		 */
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   231
		symbol_c *desired_datatype = base_type(fp_iterator.param_type());
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   232
		if ((NULL != param_name) && (NULL == desired_datatype)) ERROR;
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   233
		if ((NULL == param_name) && (NULL != desired_datatype)) ERROR;
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   234
450
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   235
		/* set the desired data type for this parameter */
425
c8e6cf57324a Print error messages when datatype erros found in ST function/FB calls.
Mario de Sousa <msousa@fe.up.pt>
parents: 424
diff changeset
   236
		set_datatype(desired_datatype, call_param_value);
450
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   237
		/* And recursively call that parameter/expression, so it can propagate that info */
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   238
		call_param_value->accept(*this);
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   239
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   240
		/* set the extensible_parameter_highest_index, which will be needed in stage 4 */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   241
		/* This value says how many extensible parameters are being passed to the standard function */
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: 423
diff changeset
   242
		if (NULL != param_name) 
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: 423
diff changeset
   243
			if (extensible_parameter_highest_index < fp_iterator.extensible_param_index())
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: 423
diff changeset
   244
				extensible_parameter_highest_index = fp_iterator.extensible_param_index();
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   245
	}
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   246
	/* call is compatible! */
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   247
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   248
	/* In the case of a call to an extensible function, we store the highest index 
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
   249
	 * of the extensible parameters this particular call uses, in the symbol_c object
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   250
	 * of the function call itself!
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   251
	 * In calls to non-extensible functions, this value will be set to -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
   252
	 * This information is later used in stage4 to correctly generate 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
   253
	 * output 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
   254
	 */
421
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   255
	if ((NULL != ext_parm_count) && (extensible_parameter_highest_index >=0) /* if call to extensible function */)
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   256
		*ext_parm_count = 1 + extensible_parameter_highest_index - fp_iterator.first_extensible_param_index();
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   257
}
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   258
840cb1e1e177 Add support in stage 3 for checking function invocations in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 417
diff changeset
   259
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   260
/*
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   261
typedef struct {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   262
  symbol_c *function_name,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   263
  symbol_c *nonformal_operand_list,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   264
  symbol_c *   formal_operand_list,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   265
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   266
  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: 428
diff changeset
   267
  symbol_c &*called_function_declaration,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   268
  int      &extensible_param_count
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   269
} generic_function_call_t;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   270
*/
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   271
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: 428
diff changeset
   272
	/* set the called_function_declaration. */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   273
	fcall_data.called_function_declaration = NULL;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   274
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   275
	/* set the called_function_declaration taking into account the datatype that we need to return */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   276
	for(unsigned int i = 0; i < fcall->candidate_datatypes.size(); i++) {
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 675
diff changeset
   277
		if (get_datatype_info_c::is_type_equal(fcall->candidate_datatypes[i], fcall->datatype)) {
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   278
			fcall_data.called_function_declaration = fcall_data.candidate_functions[i];
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   279
			break;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   280
		}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   281
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   282
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   283
	/* NOTE: If we can't figure out the declaration of the function being called, this is not 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   284
	 *       necessarily an internal compiler error. It could be because the symbol->datatype is NULL
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   285
	 *       (because the ST code being analysed has an error _before_ this function invocation).
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   286
	 *       However, we don't just give, up, we carry on recursivly analysing the code, so as to be
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   287
	 *       able to print out any error messages related to the parameters being passed in this function 
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   288
	 *       invocation.
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   289
	 */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   290
	/* if (NULL == symbol->called_function_declaration) ERROR; */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   291
	if (fcall->candidate_datatypes.size() == 1) {
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   292
		/* If only one function declaration, then we use that (even if symbol->datatypes == NULL)
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   293
		 * so we can check for errors in the expressions used to pass parameters in this
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   294
		 * function invocation.
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   295
		 */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   296
		fcall_data.called_function_declaration = fcall_data.candidate_functions[0];
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   297
	}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   298
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   299
	/* If an overloaded function is being invoked, and we cannot determine which version to use,
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   300
	 * then we can not meaningfully verify the expressions used inside that function invocation.
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   301
	 * We simply give up!
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   302
	 */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   303
	if (NULL == fcall_data.called_function_declaration)
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   304
		return;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   305
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   306
	if (NULL != fcall_data.nonformal_operand_list)  narrow_nonformal_call(fcall, fcall_data.called_function_declaration, &(fcall_data.extensible_param_count));
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   307
	if (NULL != fcall_data.   formal_operand_list)     narrow_formal_call(fcall, fcall_data.called_function_declaration, &(fcall_data.extensible_param_count));
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   308
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   309
	return;
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   310
}
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   311
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   312
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
   313
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: 445
diff changeset
   314
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: 445
diff changeset
   315
/* narrow implicit FB call in IL.
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: 445
diff changeset
   316
 * e.g.  CLK ton_var
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: 445
diff changeset
   317
 *        CU counter_var
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: 445
diff changeset
   318
 *
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: 445
diff changeset
   319
 * The algorithm will be to build a fake il_fb_call_c equivalent to the implicit IL FB call, and let 
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: 445
diff changeset
   320
 * the visit(il_fb_call_c *) method handle it!
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: 445
diff changeset
   321
 */
456
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   322
void *narrow_candidate_datatypes_c::narrow_implicit_il_fb_call(symbol_c *il_instruction, const char *param_name, symbol_c *&called_fb_declaration) {
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   323
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   324
	/* set the datatype of the il_operand, this is, the FB being called! */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   325
	if (NULL != il_operand) {
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
   326
		set_datatype(called_fb_declaration, il_operand); /* only set it if it is in the candidate datatypes list! */  
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   327
		il_operand->accept(*this);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   328
	}
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   329
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   330
	if (0 == fake_prev_il_instruction->prev_il_instruction.size()) {
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: 445
diff changeset
   331
		/* This IL implicit FB call (e.g. CLK ton_var) is not preceded by another IL instruction
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: 445
diff changeset
   332
		 * (or list of instructions) that will set the IL current/default value.
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   333
		 * We cannot proceed verifying type compatibility of something that does not exist.
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: 445
diff changeset
   334
		 */
456
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   335
		return NULL;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   336
	}
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: 445
diff changeset
   337
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
   338
	symbol_c *fb_decl = (NULL == il_operand)? NULL : il_operand->datatype;
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
   339
	
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   340
	if (NULL == fb_decl) {
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
   341
		/* the il_operand is a not FB instance, or it simply does not even exist, */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   342
		/* so we simply pass on the required datatype to the prev_il_instructions */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   343
		/* The invalid FB invocation will be caught in the print_datatypes_error_c by analysing NULL value in il_operand->datatype! */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   344
		set_datatype_in_prev_il_instructions(il_instruction->datatype, fake_prev_il_instruction);
456
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   345
		return NULL;
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   346
	}
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   347
	
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   348
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   349
	/* The value being passed to the 'param_name' parameter is actually the prev_il_instruction.
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   350
	 * However, we do not place that object directly in the fake il_param_list_c that we will be
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   351
	 * creating, since the visit(il_fb_call_c *) method will recursively call every object in that list.
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   352
	 * The il_prev_intruction object will be visited once we have handled this implici IL FB call
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   353
	 * (called from the instruction_list_c for() loop that works backwards). We DO NOT want to visit it twice.
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   354
	 * (Anyway, if we let the visit(il_fb_call_c *) recursively visit the current prev_il_instruction, this pointer
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   355
	 * would be changed to the IL instruction coming before the current prev_il_instruction! => things would get all messed up!)
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   356
	 * The easiest way to work around this is to simply use a new object, and copy the relevant details to that object!
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   357
	 */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   358
	symbol_c param_value = *fake_prev_il_instruction; /* copy the candidate_datatypes list ! */
461
fcbc0927fc96 Remove spurious printf()s, used during debugging session.
Mario de Sousa <msousa@fe.up.pt>
parents: 459
diff changeset
   359
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: 445
diff changeset
   360
	identifier_c variable_name(param_name);
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: 445
diff changeset
   361
	// SYM_REF1(il_assign_operator_c, variable_name)
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: 445
diff changeset
   362
	il_assign_operator_c il_assign_operator(&variable_name);  
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: 445
diff changeset
   363
	// SYM_REF3(il_param_assignment_c, il_assign_operator, il_operand, simple_instr_list)
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   364
	il_param_assignment_c il_param_assignment(&il_assign_operator, &param_value/*il_operand*/, NULL);
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   365
	il_param_list_c il_param_list;
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: 445
diff changeset
   366
	il_param_list.add_element(&il_param_assignment);
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: 445
diff changeset
   367
	// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   368
	CAL_operator_c CAL_operator;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   369
	il_fb_call_c il_fb_call(&CAL_operator, il_operand, NULL, &il_param_list);
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   370
	        
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: 445
diff changeset
   371
	/* A FB call does not return any datatype, but the IL instructions that come after 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: 445
diff changeset
   372
	 * FB call may require a specific datatype in the il current/default variable, 
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: 445
diff changeset
   373
	 * so we must pass this information up to the IL instruction before the FB call, since it will
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: 445
diff changeset
   374
	 * be that IL instruction that will be required to produce the desired dtataype.
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: 445
diff changeset
   375
	 *
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: 445
diff changeset
   376
	 * The above will be done by the visit(il_fb_call_c *) method, so we must make sure to
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: 445
diff changeset
   377
	 * correctly set up the il_fb_call.datatype variable!
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: 445
diff changeset
   378
	 */
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   379
	il_fb_call.called_fb_declaration = called_fb_declaration;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   380
	il_fb_call.accept(*this);
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   381
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   382
	/* set the required datatype of the previous IL instruction! */
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   383
	/* NOTE:
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   384
	 * When handling these implicit IL calls, the parameter_value being passed to the FB parameter
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   385
	 * is actually the prev_il_instruction.
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   386
	 * 
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   387
	 * However, since the FB call does not change the value in the current/default IL variable, this value
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   388
	 * must also be used ny the IL instruction coming after this FB call.
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   389
	 *
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   390
	 * This means that we have two consumers/users for the same value. 
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   391
	 * We must therefore check whether the datatype required by the IL instructions following this FB call 
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   392
	 * is the same as that required for the first parameter. If not, then we have a semantic error,
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   393
	 * and we set it to invalid_type_name.
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   394
	 *
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   395
	 * However, we only do that if:
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   396
	 *  - The IL instruction that comes after this IL FB call actually asked this FB call for a specific 
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   397
	 *     datatype in the current/default vairable, once this IL FB call returns.
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   398
	 *     However, sometimes, (for e.g., this FB call is the last in the IL list) the subsequent FB to not aks this
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   399
	 *     FB call for any datatype. In that case, then the datatype required to pass to the first parameter of the
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   400
	 *     FB call must be left unchanged!
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   401
	 */
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 675
diff changeset
   402
	if ((NULL == il_instruction->datatype) || (get_datatype_info_c::is_type_equal(param_value.datatype, il_instruction->datatype))) {
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   403
		set_datatype_in_prev_il_instructions(param_value.datatype, fake_prev_il_instruction);
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   404
	} else {
693
51a2fa6441b9 Prepare to delete search_constant_type_c -> Move the static variables from search_constant_type_c to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 690
diff changeset
   405
		set_datatype_in_prev_il_instructions(&get_datatype_info_c::invalid_type_name, fake_prev_il_instruction);
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
   406
	}
456
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
   407
	return NULL;
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
   408
}
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: 445
diff changeset
   409
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: 445
diff changeset
   410
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
   411
/* 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
   412
symbol_c *narrow_candidate_datatypes_c::base_type(symbol_c *symbol) {
718
a9f8cc778444 Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
   413
	/* NOTE: symbol == NULL is valid. It will occur when, for e.g., an undefined/undeclared symbolic_variable is used in the code. */
423
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
   414
	if (symbol == NULL) return NULL;
718
a9f8cc778444 Make search_base_type_c a singleton!
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
   415
	return search_base_type_c::get_basetype_decl(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
   416
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   417
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   418
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   419
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
   420
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   421
/**********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   422
/* 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
   423
/**********************/
797
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   424
/***********************************/
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   425
/* B 1.3.1 - Elementary Data Types */
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   426
/***********************************/
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   427
/* NOTE: elementary datatypes are their own basetype ! */
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   428
void *narrow_candidate_datatypes_c::visit(    time_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   429
void *narrow_candidate_datatypes_c::visit(    bool_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   430
void *narrow_candidate_datatypes_c::visit(    sint_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   431
void *narrow_candidate_datatypes_c::visit(    int_type_name_c     *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   432
void *narrow_candidate_datatypes_c::visit(    dint_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   433
void *narrow_candidate_datatypes_c::visit(    lint_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   434
void *narrow_candidate_datatypes_c::visit(    usint_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   435
void *narrow_candidate_datatypes_c::visit(    uint_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   436
void *narrow_candidate_datatypes_c::visit(    udint_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   437
void *narrow_candidate_datatypes_c::visit(    ulint_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   438
void *narrow_candidate_datatypes_c::visit(    real_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   439
void *narrow_candidate_datatypes_c::visit(    lreal_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   440
void *narrow_candidate_datatypes_c::visit(    date_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   441
void *narrow_candidate_datatypes_c::visit(    tod_type_name_c     *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   442
void *narrow_candidate_datatypes_c::visit(    dt_type_name_c      *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   443
void *narrow_candidate_datatypes_c::visit(    byte_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   444
void *narrow_candidate_datatypes_c::visit(    word_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   445
void *narrow_candidate_datatypes_c::visit(    dword_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   446
void *narrow_candidate_datatypes_c::visit(    lword_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   447
void *narrow_candidate_datatypes_c::visit(    string_type_name_c  *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   448
void *narrow_candidate_datatypes_c::visit(    wstring_type_name_c *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   449
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   450
void *narrow_candidate_datatypes_c::visit(safetime_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   451
void *narrow_candidate_datatypes_c::visit(safebool_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   452
void *narrow_candidate_datatypes_c::visit(safesint_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   453
void *narrow_candidate_datatypes_c::visit(safeint_type_name_c     *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   454
void *narrow_candidate_datatypes_c::visit(safedint_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   455
void *narrow_candidate_datatypes_c::visit(safelint_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   456
void *narrow_candidate_datatypes_c::visit(safeusint_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   457
void *narrow_candidate_datatypes_c::visit(safeuint_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   458
void *narrow_candidate_datatypes_c::visit(safeudint_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   459
void *narrow_candidate_datatypes_c::visit(safeulint_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   460
void *narrow_candidate_datatypes_c::visit(safereal_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   461
void *narrow_candidate_datatypes_c::visit(safelreal_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   462
void *narrow_candidate_datatypes_c::visit(safedate_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   463
void *narrow_candidate_datatypes_c::visit(safetod_type_name_c     *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   464
void *narrow_candidate_datatypes_c::visit(safedt_type_name_c      *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   465
void *narrow_candidate_datatypes_c::visit(safebyte_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   466
void *narrow_candidate_datatypes_c::visit(safeword_type_name_c    *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   467
void *narrow_candidate_datatypes_c::visit(safedword_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   468
void *narrow_candidate_datatypes_c::visit(safelword_type_name_c   *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   469
void *narrow_candidate_datatypes_c::visit(safestring_type_name_c  *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   470
void *narrow_candidate_datatypes_c::visit(safewstring_type_name_c *symbol) {symbol->datatype = search_base_type_c::get_basetype_decl(symbol); return NULL;} 
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   471
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   472
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   473
/********************************/
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   474
/* B.1.3.2 - Generic data types */
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   475
/********************************/
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   476
/* empty!! */
3444c331efc9 Fill in the symbol->datatype of elementary datatypes.
Mario de Sousa <msousa@fe.up.pt>
parents: 728
diff changeset
   477
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
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   479
/* B 1.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
   480
/********************************/
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   481
void *narrow_candidate_datatypes_c::narrow_spec_init(symbol_c *symbol, symbol_c *type_decl, symbol_c *init_value) {
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   482
	// If we are handling an anonymous datatype (i.e. a datatype implicitly declared inside a VAR ... END_VAR declaration)
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   483
	// then the symbol->datatype has not yet been set by the previous visit(type_decl) method, because it does not exist!
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   484
	// So we set the datatype ourselves!
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   485
	if ((NULL == symbol->datatype) && (symbol->candidate_datatypes.size() == 1))
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   486
		symbol->datatype = symbol->candidate_datatypes[0];
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   487
  
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   488
	set_datatype(symbol->datatype, type_decl);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   489
	type_decl->accept(*this);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   490
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   491
	if (NULL != init_value) {
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   492
		set_datatype(symbol->datatype, init_value);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   493
		init_value->accept(*this);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   494
	}
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   495
	return NULL;
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   496
}
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   497
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   498
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   499
void *narrow_candidate_datatypes_c::narrow_type_decl(symbol_c *symbol, symbol_c *type_name, symbol_c *spec_init) {
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   500
	if (symbol->candidate_datatypes.size() == 1) {
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   501
		symbol->datatype = symbol->candidate_datatypes[0];
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   502
  
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   503
		set_datatype(symbol->datatype, type_name);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   504
		set_datatype(symbol->datatype, spec_init);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   505
		spec_init->accept(*this);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   506
	}
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   507
	return NULL;
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   508
}
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   509
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   510
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   511
/*  TYPE type_declaration_list END_TYPE */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   512
// SYM_REF1(data_type_declaration_c, type_declaration_list)
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   513
/* NOTE: Not required. already handled by iterator_visitor_c base class */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   514
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   515
/* helper symbol for data_type_declaration */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   516
// SYM_LIST(type_declaration_list_c)
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   517
/* NOTE: Not required. already handled by iterator_visitor_c base class */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   518
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   519
/*  simple_type_name ':' simple_spec_init */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   520
// SYM_REF2(simple_type_declaration_c, simple_type_name, simple_spec_init)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   521
void *narrow_candidate_datatypes_c::visit(simple_type_declaration_c *symbol) {return narrow_type_decl(symbol, symbol->simple_type_name, symbol->simple_spec_init);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   522
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   523
/* 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
   524
// SYM_REF2(simple_spec_init_c, simple_specification, constant)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   525
void *narrow_candidate_datatypes_c::visit(simple_spec_init_c *symbol) {return narrow_spec_init(symbol, symbol->simple_specification, symbol->constant);}
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   526
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   527
/*  subrange_type_name ':' subrange_spec_init */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   528
// SYM_REF2(subrange_type_declaration_c, subrange_type_name, subrange_spec_init)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   529
void *narrow_candidate_datatypes_c::visit(subrange_type_declaration_c *symbol) {return narrow_type_decl(symbol, symbol->subrange_type_name, symbol->subrange_spec_init);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   530
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   531
/* subrange_specification ASSIGN signed_integer */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   532
// SYM_REF2(subrange_spec_init_c, subrange_specification, signed_integer)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   533
void *narrow_candidate_datatypes_c::visit(subrange_spec_init_c *symbol) {return narrow_spec_init(symbol, symbol->subrange_specification, symbol->signed_integer);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   534
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   535
/*  integer_type_name '(' subrange')' */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   536
// SYM_REF2(subrange_specification_c, integer_type_name, subrange)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   537
void *narrow_candidate_datatypes_c::visit(subrange_specification_c *symbol) {
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   538
	set_datatype(symbol->datatype, symbol->integer_type_name);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   539
	symbol->integer_type_name->accept(*this);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   540
	set_datatype(symbol->datatype, symbol->integer_type_name);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   541
	symbol->integer_type_name->accept(*this);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   542
	return NULL;
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   543
}
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   544
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
   545
/*  signed_integer DOTDOT signed_integer */
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   546
/* dimension will be filled in during stage 3 (array_range_check_c) with the number of elements in this subrange */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   547
// SYM_REF2(subrange_c, lower_limit, upper_limit, unsigned long long int dimension;)
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
void *narrow_candidate_datatypes_c::visit(subrange_c *symbol) {
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   549
	set_datatype(symbol->datatype, symbol->lower_limit);
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
   550
	symbol->lower_limit->accept(*this);
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   551
	set_datatype(symbol->datatype, symbol->upper_limit);
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
   552
	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
   553
	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
   554
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   555
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   557
/*  enumerated_type_name ':' enumerated_spec_init */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   558
// SYM_REF2(enumerated_type_declaration_c, enumerated_type_name, enumerated_spec_init)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   559
void *narrow_candidate_datatypes_c::visit(enumerated_type_declaration_c *symbol) {return narrow_type_decl(symbol, symbol->enumerated_type_name, symbol->enumerated_spec_init);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   560
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   561
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   562
/* enumerated_specification ASSIGN enumerated_value */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   563
// SYM_REF2(enumerated_spec_init_c, enumerated_specification, enumerated_value)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   564
void *narrow_candidate_datatypes_c::visit(enumerated_spec_init_c *symbol) {return narrow_spec_init(symbol, symbol->enumerated_specification, symbol->enumerated_value);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   565
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   566
/* helper symbol for enumerated_specification->enumerated_spec_init */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   567
/* enumerated_value_list ',' enumerated_value */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   568
// SYM_LIST(enumerated_value_list_c)
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   569
void *narrow_candidate_datatypes_c::visit(enumerated_value_list_c *symbol) {
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   570
//if (NULL == symbol->datatype) ERROR;  // Comented out-> Reserve this check for the print_datatypes_error_c ???  
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   571
  for(int i = 0; i < symbol->n; i++) set_datatype(symbol->datatype, symbol->elements[i]);
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   572
//for(int i = 0; i < symbol->n; i++) if (NULL == symbol->elements[i]->datatype) ERROR; // Comented out-> Reserve this check for the print_datatypes_error_c ???  
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   573
  return NULL;  
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   574
}
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   575
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   576
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   577
/* enumerated_type_name '#' identifier */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   578
// SYM_REF2(enumerated_value_c, type, value)
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   579
// void *narrow_candidate_datatypes_c::visit(enumerated_value_c *symbol) {/* do nothing! */ return NULL;}
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   580
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   581
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   582
/*  identifier ':' array_spec_init */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   583
// SYM_REF2(array_type_declaration_c, identifier, array_spec_init)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   584
void *narrow_candidate_datatypes_c::visit(array_type_declaration_c *symbol) {return narrow_type_decl(symbol, symbol->identifier, symbol->array_spec_init);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   585
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   586
/* array_specification [ASSIGN array_initialization} */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   587
/* array_initialization may be NULL ! */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   588
// SYM_REF2(array_spec_init_c, array_specification, array_initialization)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   589
void *narrow_candidate_datatypes_c::visit(array_spec_init_c *symbol) {return narrow_spec_init(symbol, symbol->array_specification, symbol->array_initialization);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   590
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   591
/* ARRAY '[' array_subrange_list ']' OF non_generic_type_name */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   592
// SYM_REF2(array_specification_c, array_subrange_list, non_generic_type_name)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   593
// Not needed!!
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   594
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   595
/* helper symbol for array_specification */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   596
/* array_subrange_list ',' subrange */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   597
// SYM_LIST(array_subrange_list_c)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   598
// Not needed ??
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   599
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   600
/* array_initialization:  '[' array_initial_elements_list ']' */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   601
/* helper symbol for array_initialization */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   602
/* array_initial_elements_list ',' array_initial_elements */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   603
// SYM_LIST(array_initial_elements_list_c)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   604
// Not needed ???
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   605
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   606
/* integer '(' [array_initial_element] ')' */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   607
/* array_initial_element may be NULL ! */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   608
// SYM_REF2(array_initial_elements_c, integer, array_initial_element)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   609
// Not needed ???
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   610
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   611
/*  structure_type_name ':' structure_specification */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   612
// SYM_REF2(structure_type_declaration_c, structure_type_name, structure_specification)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   613
void *narrow_candidate_datatypes_c::visit(structure_type_declaration_c *symbol) {return narrow_type_decl(symbol, symbol->structure_type_name, symbol->structure_specification);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   614
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   615
/* structure_type_name ASSIGN structure_initialization */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   616
/* structure_initialization may be NULL ! */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   617
// SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   618
void *narrow_candidate_datatypes_c::visit(initialized_structure_c *symbol) {return narrow_spec_init(symbol, symbol->structure_type_name, symbol->structure_initialization);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   619
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   620
/* helper symbol for structure_declaration */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   621
/* structure_declaration:  STRUCT structure_element_declaration_list END_STRUCT */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   622
/* structure_element_declaration_list structure_element_declaration ';' */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   623
// SYM_LIST(structure_element_declaration_list_c)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   624
// Not needed ???
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   625
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   626
/*  structure_element_name ':' *_spec_init */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   627
// SYM_REF2(structure_element_declaration_c, structure_element_name, spec_init)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   628
// Not needed ???
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   629
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   630
/* helper symbol for structure_initialization */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   631
/* structure_initialization: '(' structure_element_initialization_list ')' */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   632
/* structure_element_initialization_list ',' structure_element_initialization */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   633
// SYM_LIST(structure_element_initialization_list_c)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   634
// Not needed ???
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   635
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   636
/*  structure_element_name ASSIGN value */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   637
// SYM_REF2(structure_element_initialization_c, structure_element_name, value)
806
f218434eeaf8 Fill in the symbol.datatype annotation in symbol classes used in derived data type declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 798
diff changeset
   638
// Not needed ???
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   639
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   640
/*  string_type_name ':' elementary_string_type_name string_type_declaration_size string_type_declaration_init */
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   641
// SYM_REF4(string_type_declaration_c, string_type_name, elementary_string_type_name, string_type_declaration_size, string_type_declaration_init/* may be == NULL! */) 
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   642
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   643
810
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 808
diff changeset
   644
/* structure_type_name ASSIGN structure_initialization */
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 808
diff changeset
   645
/* structure_initialization may be NULL ! */
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 808
diff changeset
   646
// SYM_REF2(initialized_structure_c, structure_type_name, structure_initialization)
d9c48ad646f1 Add a new node to the abstract symtax tree, which will let us do datatype checking of FB variable declarations using the standard algorithm, and no special cases.
Mario de Sousa <msousa@fe.up.pt>
parents: 808
diff changeset
   647
void *narrow_candidate_datatypes_c::visit(fb_spec_init_c *symbol) {return narrow_spec_init(symbol, symbol->function_block_type_name, symbol->structure_initialization);}
726
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   648
9b61eb4f00dc Change the base datatype of enumerations to an enumerated_type_declaration_c (for named types!)
Mario de Sousa <msousa@fe.up.pt>
parents: 718
diff changeset
   649
909
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   650
/* REF_TO (non_generic_type_name | function_block_type_name) */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   651
// SYM_REF1(ref_spec_c, type_name)
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   652
void *narrow_candidate_datatypes_c::visit(ref_spec_c *symbol) {
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   653
	/* First handle the datatype being referenced (pointed to) */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   654
	if (symbol->type_name->candidate_datatypes.size() == 1) {
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   655
		symbol->type_name->datatype = symbol->type_name->candidate_datatypes[0];
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   656
		symbol->type_name->accept(*this);
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   657
	}
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   658
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   659
	/* Now handle the reference datatype itself (i.e. the pointer) */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   660
	// If we are handling an anonymous datatype (i.e. a datatype implicitly declared inside a VAR ... END_VAR declaration)
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   661
	// then the symbol->datatype has not yet been set by the previous visit(type_decl) method, because it does not exist!
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   662
	// So we set the datatype ourselves!
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   663
	if ((NULL == symbol->datatype) && (symbol->candidate_datatypes.size() == 1))
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   664
		symbol->datatype = symbol->candidate_datatypes[0];
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   665
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   666
	return NULL;
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   667
}
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   668
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   669
/* For the moment, we do not support initialising reference data types */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   670
/* ref_spec [ ASSIGN ref_initialization ] */ 
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   671
/* NOTE: ref_initialization may be NULL!! */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   672
// SYM_REF2(ref_spec_init_c, ref_spec, ref_initialization)
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   673
void *narrow_candidate_datatypes_c::visit(ref_spec_init_c *symbol) {return narrow_spec_init(symbol, symbol->ref_spec, symbol->ref_initialization);}
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   674
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   675
/* identifier ':' ref_spec_init */
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   676
// SYM_REF2(ref_type_decl_c, ref_type_name, ref_spec_init)
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   677
void *narrow_candidate_datatypes_c::visit(ref_type_decl_c *symbol) {return narrow_type_decl(symbol, symbol->ref_type_name, symbol->ref_spec_init);}
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   678
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   679
8b2a31dea131 Add support for REF_TO derived datatypes (along with datatype verification)
mjsousa
parents: 895
diff changeset
   680
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
/* 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
   683
/*********************/
843
f9a059c24aea Fill in the 'datatype' anotation in the identifiers of symbolic variables.
mjsousa
parents: 839
diff changeset
   684
// SYM_REF1(symbolic_variable_c, var_name)
f9a059c24aea Fill in the 'datatype' anotation in the identifiers of symbolic variables.
mjsousa
parents: 839
diff changeset
   685
void *narrow_candidate_datatypes_c::visit(symbolic_variable_c *symbol) {
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   686
	symbol->scope = current_scope;  // the scope in which this variable was declared!
843
f9a059c24aea Fill in the 'datatype' anotation in the identifiers of symbolic variables.
mjsousa
parents: 839
diff changeset
   687
	symbol->var_name->datatype = symbol->datatype;
f9a059c24aea Fill in the 'datatype' anotation in the identifiers of symbolic variables.
mjsousa
parents: 839
diff changeset
   688
	return NULL;
f9a059c24aea Fill in the 'datatype' anotation in the identifiers of symbolic variables.
mjsousa
parents: 839
diff changeset
   689
}
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
   690
/********************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   691
/* 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
   692
/********************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   693
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   696
/*************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/*  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
   698
// 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
   699
void *narrow_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
   700
	/* we need to 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
   701
	symbol->subscript_list->accept(*this);
827
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   702
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   703
	/* Set the datatype of the subscripted variable and visit it recursively. For the reason why we do this,                                                 */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   704
	/* Please read the comments in the array_variable_c and structured_variable_c visitors in the fill_candidate_datatypes.cc file! */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   705
	symbol->subscripted_variable->accept(*this); // visit recursively
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   706
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   707
	if (symbol->subscripted_variable->candidate_datatypes.size() == 1)
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   708
	  symbol->subscripted_variable->datatype = symbol->subscripted_variable->candidate_datatypes[0]; // set the datatype
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   709
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   710
	// the scope in which this variable was declared! It will be the same as the subscripted variable (a symbolic_variable_ !)
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   711
	symbol->scope = symbol->subscripted_variable->scope;	
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   712
	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
   713
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   714
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   715
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   716
/* 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
   717
// 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
   718
void *narrow_candidate_datatypes_c::visit(subscript_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
   719
	for (int i = 0; i < symbol->n; 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
   720
		for (unsigned int k = 0; k < symbol->elements[i]->candidate_datatypes.size(); k++) {
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
   721
			if (get_datatype_info_c::is_ANY_INT(symbol->elements[i]->candidate_datatypes[k]))
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
   722
				symbol->elements[i]->datatype = symbol->elements[i]->candidate_datatypes[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
   723
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   724
		symbol->elements[i]->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
   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
	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
   727
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   728
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   729
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   730
827
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   731
/*  record_variable '.' field_selector */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   732
/*  WARNING: input and/or output variables of function blocks
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   733
 *           may be accessed as fields of a structured variable!
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   734
 *           Code handling a structured_variable_c must take
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   735
 *           this into account!
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   736
 */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   737
// SYM_REF2(structured_variable_c, record_variable, field_selector)
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   738
void *narrow_candidate_datatypes_c::visit(structured_variable_c *symbol) {
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   739
	/* Set the datatype of the record_variable and visit it recursively. For the reason why we do this,                                                      */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   740
	/* Please read the comments in the array_variable_c and structured_variable_c visitors in the fill_candidate_datatypes.cc file! */
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   741
	symbol->record_variable->accept(*this); // visit recursively
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   742
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   743
	if (symbol->record_variable->candidate_datatypes.size() == 1)
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   744
	  symbol->record_variable->datatype = symbol->record_variable->candidate_datatypes[0]; // set the datatype
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   745
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   746
	symbol->scope = symbol->record_variable->datatype;	// the scope in which this variable was declared!
827
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   747
	return NULL;
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   748
}
e3800aff352c Fix datatype analysis of structured variables that contain arrays in their fields (e.g. var.x1[var2 + 42].y1).
mjsousa
parents: 813
diff changeset
   749
502
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   750
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   751
/******************************************/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   752
/* 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
   753
/******************************************/
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   754
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   755
void *narrow_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
   756
#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
   757
  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
   758
    if (symbol->elements[i]->candidate_datatypes.size() == 1)
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   759
      symbol->elements[i]->datatype = symbol->elements[i]->candidate_datatypes[0];
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   760
  }
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   761
#endif
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   762
  return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   763
}  
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   764
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   765
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   766
/*  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
   767
// 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
   768
void *narrow_candidate_datatypes_c::visit(location_c *symbol) {
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   769
  set_datatype(symbol->datatype, symbol->direct_variable);
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   770
  symbol->direct_variable->accept(*this); /* currently does nothing! */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   771
  return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   772
}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   773
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   774
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   775
/*  [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
   776
/* 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
   777
// 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
   778
void *narrow_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
   779
  /* let the var_spec_init set its own symbol->datatype value */
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   780
  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
   781
  
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   782
  if (NULL != symbol->variable_name)
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   783
    set_datatype(symbol->located_var_spec_init->datatype, symbol->variable_name);
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   784
    
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   785
  set_datatype(symbol->located_var_spec_init->datatype, symbol->location);
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   786
  symbol->location->accept(*this);
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   787
  return NULL;
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   788
}
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   789
a6211f73690b Start data type checking of var declarations (including direct variables!)
Mario de Sousa <msousa@fe.up.pt>
parents: 490
diff changeset
   790
808
7a6b53d61ea3 Consider fb_name_decl_c a non base data type class!
Mario de Sousa <msousa@fe.up.pt>
parents: 807
diff changeset
   791
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
   792
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   793
/* 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
   794
/************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   795
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   796
/* 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
   797
/*********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   798
void *narrow_candidate_datatypes_c::visit(function_declaration_c *symbol) {
798
d21e598b0b75 Set the symbol->datatpe of function_declaration_c
Mario de Sousa <msousa@fe.up.pt>
parents: 797
diff changeset
   799
	/* set the function_declaration_c->datatype to the datatype returned by the function! */
d21e598b0b75 Set the symbol->datatpe of function_declaration_c
Mario de Sousa <msousa@fe.up.pt>
parents: 797
diff changeset
   800
	symbol->type_name->datatype = search_base_type_c::get_basetype_decl(symbol->type_name);
d21e598b0b75 Set the symbol->datatpe of function_declaration_c
Mario de Sousa <msousa@fe.up.pt>
parents: 797
diff changeset
   801
	symbol->datatype = symbol->type_name->datatype;
d21e598b0b75 Set the symbol->datatpe of function_declaration_c
Mario de Sousa <msousa@fe.up.pt>
parents: 797
diff changeset
   802
	
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   803
	current_scope = 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
   804
	search_varfb_instance_type = new search_varfb_instance_type_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: 441
diff changeset
   805
	symbol->var_declarations_list->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   806
	if (debug) printf("Narrowing candidate data types list in body of function %s\n", ((token_c *)(symbol->derived_function_name))->value);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   807
	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
   808
	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
   809
	search_varfb_instance_type = NULL;
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   810
	current_scope = 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
   811
	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
   812
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   813
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   814
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   815
/* 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
   816
/***************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   817
void *narrow_candidate_datatypes_c::visit(function_block_declaration_c *symbol) {
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   818
	current_scope = 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
   819
	search_varfb_instance_type = new search_varfb_instance_type_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: 441
diff changeset
   820
	symbol->var_declarations->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   821
	if (debug) printf("Narrowing candidate data types list in body of FB %s\n", ((token_c *)(symbol->fblock_name))->value);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   822
	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
   823
	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
   824
	search_varfb_instance_type = NULL;
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   825
	current_scope = NULL;	
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   826
807
4d71292f8732 Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 806
diff changeset
   827
	// A FB declaration can also be used as a Datatype! We now do the narrow algorithm considering it as such!
4d71292f8732 Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 806
diff changeset
   828
	if (symbol->candidate_datatypes.size() == 1)
4d71292f8732 Fill symbol->datatype anotation for FB declarations.
Mario de Sousa <msousa@fe.up.pt>
parents: 806
diff changeset
   829
		symbol->datatype = symbol->candidate_datatypes[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
   830
	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
   831
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   832
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   833
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   834
/* 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
   835
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   836
void *narrow_candidate_datatypes_c::visit(program_declaration_c *symbol) {
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   837
	current_scope = 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
   838
	search_varfb_instance_type = new search_varfb_instance_type_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: 441
diff changeset
   839
	symbol->var_declarations->accept(*this);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   840
	if (debug) printf("Narrowing candidate data types list in body of program %s\n", ((token_c *)(symbol->program_type_name))->value);
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   841
	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
   842
	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
   843
	search_varfb_instance_type = NULL;
889
5f380b99e95e Correctly handle structured variables that include FB and external FBs (example: FB1.FB2.extFB3.FB4.extFB5.extFB6.structvar.field1 := 42;) (this commit fixes only ST code. TODO: IL and SFC)
mjsousa
parents: 873
diff changeset
   844
	current_scope = 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
   845
	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
   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
802
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   848
/********************************************/
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   849
/* B 1.6 Sequential function chart elements */
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   850
/********************************************/
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   851
void *narrow_candidate_datatypes_c::visit(transition_condition_c *symbol) {
895
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 889
diff changeset
   852
	// We can safely ask for a BOOL type, as even if the result is a SAFEBOOL, in that case it will aslo include BOOL as a possible datatype.
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 889
diff changeset
   853
	set_datatype(&get_datatype_info_c::bool_type_name /* datatype*/, symbol /* symbol */);
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 889
diff changeset
   854
802
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   855
	if (symbol->transition_condition_il != NULL) {
895
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 889
diff changeset
   856
		set_datatype(symbol->datatype, symbol->transition_condition_il);
802
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   857
		symbol->transition_condition_il->accept(*this);
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   858
	}
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   859
	if (symbol->transition_condition_st != NULL) {
895
f824bf8e1579 Add error message for invalid datatype of transition condition. Generalize datatype narrowing algorithm for transition conditions.
mjsousa
parents: 889
diff changeset
   860
		set_datatype(symbol->datatype, symbol->transition_condition_st);
802
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   861
		symbol->transition_condition_st->accept(*this);
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   862
	}
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   863
	return NULL;
cac262d1d6a5 Fixed bug with SFC transition datatype checking
Laurent Bessard
parents: 798
diff changeset
   864
}
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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   868
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *narrow_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
   870
	// 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
   871
	/* 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
   872
	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
   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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   877
/* 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
   878
/****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/***********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
   881
/***********************************/
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   882
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   883
/*| 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: 441
diff changeset
   884
// SYM_LIST(instruction_list_c)
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   885
void *narrow_candidate_datatypes_c::visit(instruction_list_c *symbol) {
450
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   886
	/* In order to execute the narrow algoritm correctly, we need to go through the instructions backwards,
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   887
	 * so we can not use the base class' visitor 
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   888
	 */
466
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   889
	/* In order to execute the narrow algoritm correctly
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   890
	 * in IL instruction lists containing JMPs to labels that come before the JMP instruction
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   891
	 * itself, we need to run the narrow algorithm twice on the Instruction List.
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   892
	 * e.g.:  ...
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   893
	 *          ld 23
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   894
	 *   label1:st byte_var
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   895
	 *          ld 34
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   896
	 *          JMP label1     
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   897
	 *
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   898
	 * Note that the second time we run the narrow, most of the datatypes are already filled
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   899
	 * in, so it will be able to produce tha correct datatypes for the IL instruction referenced
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   900
	 * by the label, as in the 2nd pass we already know the datatypes of the JMP instruction!
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   901
	 */
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   902
	for(int j = 0; j < 2; j++) {
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   903
		for(int i = symbol->n-1; i >= 0; i--) {
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   904
			symbol->elements[i]->accept(*this);
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
   905
		}
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   906
	}
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   907
	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: 441
diff changeset
   908
}
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   909
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   910
/* | 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: 441
diff changeset
   911
// 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: 441
diff changeset
   912
// 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: 441
diff changeset
   913
void *narrow_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: 445
diff changeset
   914
	if (NULL == symbol->il_instruction) {
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: 445
diff changeset
   915
		/* this empty/null il_instruction cannot generate the desired datatype. We pass on the request to the previous il instruction. */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   916
		set_datatype_in_prev_il_instructions(symbol->datatype, 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: 445
diff changeset
   917
	} else {
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   918
		il_instruction_c tmp_prev_il_instruction(NULL, NULL);
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   919
		/* the narrow algorithm will need access to the intersected candidate_datatype lists of all prev_il_instructions, as well as the 
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   920
		 * list of the prev_il_instructions.
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   921
		 * Instead of creating two 'global' (within the class) variables, we create a single il_instruction_c variable (fake_prev_il_instruction),
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   922
		 * and shove that data into this single variable.
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   923
		 */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   924
		tmp_prev_il_instruction.prev_il_instruction = symbol->prev_il_instruction;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   925
		intersect_prev_candidate_datatype_lists(&tmp_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: 445
diff changeset
   926
		/* Tell the il_instruction the datatype that it must generate - this was chosen by the next il_instruction (remember: we are iterating backwards!) */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   927
		fake_prev_il_instruction = &tmp_prev_il_instruction;
674
b221168a36f1 Set datatype of il_intruction_c objects containing an ST operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 673
diff changeset
   928
		current_il_instruction   = symbol;
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   929
		symbol->il_instruction->datatype = symbol->datatype;
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: 445
diff changeset
   930
		symbol->il_instruction->accept(*this);
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   931
		fake_prev_il_instruction = NULL;
674
b221168a36f1 Set datatype of il_intruction_c objects containing an ST operator.
Mario de Sousa <msousa@fe.up.pt>
parents: 673
diff changeset
   932
		current_il_instruction   = NULL;
450
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   933
	}
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   934
	return NULL;
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
   935
}
444
92d40d2a7adc Update comments on general architecture.
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   936
92d40d2a7adc Update comments on general architecture.
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   937
92d40d2a7adc Update comments on general architecture.
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   938
92d40d2a7adc Update comments on general architecture.
Mario de Sousa <msousa@fe.up.pt>
parents: 443
diff changeset
   939
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
   940
// void *visit(instruction_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
   941
void *narrow_candidate_datatypes_c::visit(il_simple_operation_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: 441
diff changeset
   942
	/* Tell the il_simple_operator the datatype that it must generate - this was chosen by the next il_instruction (we iterate backwards!) */
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   943
	symbol->il_simple_operator->datatype = symbol->datatype;
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
   944
	/* recursive call to see whether data types are compatible */
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
   945
	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
   946
	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
   947
	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
   948
	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
   949
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   950
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   951
/* | function_name [il_operand_list] */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   952
/* 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: 428
diff changeset
   953
// 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
   954
void *narrow_candidate_datatypes_c::visit(il_function_call_c *symbol) {
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   955
	/* The first parameter of a non formal function call in IL will be the 'current value' (i.e. the prev_il_instruction)
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   956
	 * In order to be able to handle this without coding special cases, we will simply prepend that symbol
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   957
	 * to the il_operand_list, and remove it after calling handle_function_call().
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   958
	 * However, since handle_function_call() will be recursively calling all parameter, and we don't want
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   959
	 * to do that for the prev_il_instruction (since it has already been visited by the fill_candidate_datatypes_c)
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   960
	 * we create a new ____ symbol_c ____ object, and copy the relevant info to/from that object before/after
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   961
	 * the call to handle_function_call().
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   962
	 *
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   963
	 * However, if no further paramters are given, then il_operand_list will be NULL, and we will
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   964
	 * need to create a new object to hold the pointer to prev_il_instruction.
534
d13a38011af4 Fix comment.
Mario de Sousa <msousa@fe.up.pt>
parents: 515
diff changeset
   965
	 * This change will also be undone at the end of this method.
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   966
	 */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   967
	symbol_c param_value = *fake_prev_il_instruction; /* copy the candidate_datatypes list */
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   968
	if (NULL == symbol->il_operand_list)  symbol->il_operand_list = new il_operand_list_c;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   969
	if (NULL == symbol->il_operand_list)  ERROR;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   970
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   971
	((list_c *)symbol->il_operand_list)->insert_element(&param_value, 0);
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   972
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   973
	generic_function_call_t fcall_param = {
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   974
		/* fcall_param.function_name               = */ symbol->function_name,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   975
		/* fcall_param.nonformal_operand_list      = */ symbol->il_operand_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   976
		/* fcall_param.formal_operand_list         = */ NULL,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   977
		/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_function,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   978
		/* fcall_param.candidate_functions         = */ symbol->candidate_functions,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   979
		/* fcall_param.called_function_declaration = */ symbol->called_function_declaration,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
   980
		/* 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: 428
diff changeset
   981
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   982
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
   983
	narrow_function_invocation(symbol, fcall_param);
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
   984
	set_datatype_in_prev_il_instructions(param_value.datatype, fake_prev_il_instruction);
451
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   985
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   986
	/* 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
   987
	((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
   988
	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
   989
		/* 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
   990
		delete 	symbol->il_operand_list;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   991
		symbol->il_operand_list = NULL;
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   992
	}
a1b87eb155e4 Cleaning up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 450
diff changeset
   993
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
   994
	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
   995
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   996
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
   997
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   998
/* | 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
   999
// 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
  1000
void *narrow_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
  1001
  /* first handle the operation (il_expr_operator) that will use the result coming from the parenthesised IL list (i.e. simple_instr_list) */
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1002
  symbol->il_expr_operator->datatype = symbol->datatype;
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1003
  il_operand = symbol->simple_instr_list; /* This is not a bug! The parenthesised expression will be used as the operator! */
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1004
  symbol->il_expr_operator->accept(*this);
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1005
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1006
  /* now give the parenthesised IL list a chance to narrow the datatypes */
454
099aa5d655de Finish support for semantic verification of IL paranthesised expressions.
Mario de Sousa <msousa@fe.up.pt>
parents: 453
diff changeset
  1007
  /* The datatype that is must return was set by the call symbol->il_expr_operator->accept(*this) */
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1008
  il_instruction_c *save_fake_prev_il_instruction = fake_prev_il_instruction; /*this is not really necessary, but lets play it safe */
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1009
  symbol->simple_instr_list->accept(*this);
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1010
  fake_prev_il_instruction = save_fake_prev_il_instruction;
690
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1011
  
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1012
  /* Since stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list when an 'il_operand' exists, we know
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1013
   * that if (symbol->il_operand != NULL), then the first IL instruction in the simple_instr_list will be the equivalent and artificial
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1014
   * 'LD <il_operand>' IL instruction.
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1015
   * Just to be consistent, we will copy the datatype info back into the il_operand, even though this should not be necessary!
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1016
   */
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1017
  if ((NULL != symbol->il_operand) && ((NULL == symbol->simple_instr_list) || (0 == ((list_c *)symbol->simple_instr_list)->n))) ERROR; // stage2 is not behaving as we expect it to!
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1018
  if  (NULL != symbol->il_operand)
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1019
    symbol->il_operand->datatype = ((list_c *)symbol->simple_instr_list)->elements[0]->datatype;
6156ee2b4e32 Correctly generate C code for IL expressions, i.e. IL instructions inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 676
diff changeset
  1020
  
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1021
  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
  1022
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
456
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1024
466
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1025
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1026
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1027
/*  il_jump_operator label */
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1028
void *narrow_candidate_datatypes_c::visit(il_jump_operation_c *symbol) {
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1029
  /* recursive call to fill the datatype */
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1030
  symbol->il_jump_operator->datatype = symbol->datatype;
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1031
  symbol->il_jump_operator->accept(*this);
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1032
  return NULL;
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1033
}
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1034
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1035
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1036
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1037
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1038
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1039
d97a29b7fa8b Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
Mario de Sousa <msousa@fe.up.pt>
parents: 461
diff changeset
  1040
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
  1041
/*   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
  1042
 * | 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
  1043
 * | 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
  1044
 * | 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
  1045
 * | 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
  1046
 */
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
  1047
/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 */
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
  1048
// 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
  1049
void *narrow_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
  1050
	symbol_c *fb_decl = symbol->called_fb_declaration;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1051
	
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
  1052
	/* 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
  1053
	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
  1054
	if (NULL != symbol->il_operand_list)  narrow_nonformal_call(symbol, 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
  1055
	if (NULL != symbol->  il_param_list)     narrow_formal_call(symbol, 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
  1056
455
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1057
	/* Let the il_call_operator (CAL, CALC, or CALCN) set the datatype of prev_il_instruction... */
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1058
	symbol->il_call_operator->datatype = symbol->datatype;
933c0dccc82f Add support for semantic verification of CALC, CALCN, etc..
Mario de Sousa <msousa@fe.up.pt>
parents: 454
diff changeset
  1059
	symbol->il_call_operator->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
  1060
	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
  1061
}
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
  1062
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
  1063
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1064
/* | 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: 428
diff changeset
  1065
/* 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: 428
diff changeset
  1066
// 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
  1067
void *narrow_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: 428
diff changeset
  1068
	generic_function_call_t fcall_param = {
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1069
		/* fcall_param.function_name               = */ symbol->function_name,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1070
		/* fcall_param.nonformal_operand_list      = */ NULL,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1071
		/* fcall_param.formal_operand_list         = */ symbol->il_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1072
		/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_function,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1073
		/* fcall_param.candidate_functions         = */ symbol->candidate_functions,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1074
		/* fcall_param.called_function_declaration = */ symbol->called_function_declaration,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1075
		/* 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: 428
diff changeset
  1076
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1077
  
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1078
	narrow_function_invocation(symbol, fcall_param);
450
eb1b28acec2e Fix a few more bugs related to FB/function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 448
diff changeset
  1079
	/* The desired datatype of the previous il instruction was already set by narrow_function_invocation() */
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
  1080
	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
  1081
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1082
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1083
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1084
//     void *visit(il_operand_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
  1085
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1086
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1087
/* | simple_instr_list il_simple_instruction */
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1088
/* This object is referenced by il_expression_c objects */
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1089
void *narrow_candidate_datatypes_c::visit(simple_instr_list_c *symbol) {
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1090
	if (symbol->n > 0)
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1091
		symbol->elements[symbol->n - 1]->datatype = symbol->datatype;
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1092
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1093
	for(int i = symbol->n-1; i >= 0; i--) {
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1094
		symbol->elements[i]->accept(*this);
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1095
	}
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1096
	return NULL;
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1097
}
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1098
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1099
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1100
// 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
  1101
void *narrow_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
  1102
  if (symbol->prev_il_instruction.size() > 1) ERROR; /* There should be no labeled insructions inside an IL expression! */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1103
    
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1104
  il_instruction_c tmp_prev_il_instruction(NULL, NULL);
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1105
  /* the narrow algorithm will need access to the intersected candidate_datatype lists of all prev_il_instructions, as well as the 
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1106
   * list of the prev_il_instructions.
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1107
   * Instead of creating two 'global' (within the class) variables, we create a single il_instruction_c variable (fake_prev_il_instruction),
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1108
   * and shove that data into this single variable.
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1109
   */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1110
  if (symbol->prev_il_instruction.size() > 0)
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1111
    tmp_prev_il_instruction.candidate_datatypes = symbol->prev_il_instruction[0]->candidate_datatypes;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1112
  tmp_prev_il_instruction.prev_il_instruction = symbol->prev_il_instruction;
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1113
  
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1114
   /* copy the candidate_datatypes list */
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1115
  fake_prev_il_instruction = &tmp_prev_il_instruction;
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1116
  symbol->il_simple_instruction->datatype = symbol->datatype;
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1117
  symbol->il_simple_instruction->accept(*this);
459
01f6664bf8c5 Continue adding support for semantic verification of JMP and RET.
Mario de Sousa <msousa@fe.up.pt>
parents: 457
diff changeset
  1118
  fake_prev_il_instruction = NULL;
453
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1119
  return NULL;
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1120
}
4733f662362a More changes for support of semantic verification of il_expressions
Mario de Sousa <msousa@fe.up.pt>
parents: 452
diff changeset
  1121
452
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1122
//     void *visit(il_param_list_c *symbol);
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1123
//     void *visit(il_param_assignment_c *symbol);
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1124
//     void *visit(il_param_out_assignment_c *symbol);
79ac274d1cc4 Start of support for IL expressions (parenthesis).
Mario de Sousa <msousa@fe.up.pt>
parents: 451
diff changeset
  1125
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
  1126
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1127
/*******************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1128
/* 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
  1129
/*******************/
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1130
/* Sets the datatype of the il_operand, and calls it recursively!
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1131
 * 
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1132
 * NOTE 1: the il_operand __may__ be pointing to a parenthesized list of IL instructions. 
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1133
 * e.g.  LD 33
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1134
 *       AND ( 45
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1135
 *            OR 56
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1136
 *            )
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1137
 *       When we handle the first 'AND' IL_operator, the il_operand will point to an simple_instr_list_c.
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1138
 *       In this case, when we call il_operand->accept(*this);, the prev_il_instruction pointer will be overwritten!
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1139
 *
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1140
 *       So, if yoy wish to set the prev_il_instruction->datatype = symbol->datatype;
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1141
 *       do it __before__ calling set_il_operand_datatype() (which in turn calls il_operand->accept(*this)) !!
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1142
 */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1143
void *narrow_candidate_datatypes_c::set_il_operand_datatype(symbol_c *il_operand, symbol_c *datatype) {
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1144
	if (NULL == il_operand) return NULL; /* if no IL operand => error in the source code!! */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1145
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1146
	/* If il_operand already has a non-NULL datatype (remember, narrow algorithm runs twice over IL lists!),
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1147
	 * but narrow algorithm has not yet been able to determine what datatype it should take? This is strange,
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1148
	 * and most probably an error!
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1149
	 */
838
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1150
	if ((NULL != il_operand->datatype) && (NULL == datatype)) ERROR;
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1151
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1152
	/* If the il_operand's datatype has already been set previously, and
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1153
	 * the narrow algorithm has already determined the datatype the il_operand should take!
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1154
	 *   ...we just make sure that the new datatype is the same as the current il_operand's datatype
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1155
	 */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1156
	if ((NULL != il_operand->datatype)  && (NULL != datatype)) {
838
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1157
		/* Both datatypes are an invalid_type_name_c. This implies they are the same!! */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1158
		if ((!get_datatype_info_c::is_type_valid(datatype)) && ((!get_datatype_info_c::is_type_valid(il_operand->datatype)))) 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1159
			return NULL;;
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1160
		/* OK, so both the datatypes are valid, but are they equal? */
838
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1161
		if ( !get_datatype_info_c::is_type_equal(il_operand->datatype, datatype)) 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1162
			ERROR; 
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1163
		/* The datatypes are the same. We have nothing to do, so we simply return! */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1164
		return NULL;
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1165
	}
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1166
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1167
	/* Set the il_operand's datatype. Note that the new 'datatype' may even be NULL!!! */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1168
	il_operand->datatype = datatype;
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1169
	/* Even if we are not able to determine the il_operand's datatype ('datatype' is NULL), we still visit it recursively,
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1170
	 * to give a chance of any complex expressions embedded in the il_operand (e.g. expressions inside array subscripts!) 
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1171
	 * to be narrowed too.
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1172
	 */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1173
	il_operand->accept(*this);
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1174
	return NULL;
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1175
}
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1176
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1177
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1178
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1179
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1180
void *narrow_candidate_datatypes_c::narrow_binary_operator(const struct widen_entry widen_table[], symbol_c *symbol, bool *deprecated_operation) {
478
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1181
	symbol_c *prev_instruction_type, *operand_type;
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1182
	int count = 0;
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1183
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1184
        if (NULL != deprecated_operation)
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1185
		*deprecated_operation = false;
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1186
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
  1187
	if (NULL == il_operand) return NULL; /* if no IL operand => error in the source code!! */
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
  1188
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
  1189
	 /* NOTE 1: the il_operand __may__ be pointing to a parenthesized list of IL instructions. 
478
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1190
	 * e.g.  LD 33
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1191
	 *       AND ( 45
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1192
	 *            OR 56
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1193
	 *            )
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1194
	 *       When we handle the first 'AND' IL_operator, the il_operand will point to an simple_instr_list_c.
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1195
	 *       In this case, when we call il_operand->accept(*this);, the prev_il_instruction pointer will be overwritten!
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1196
	 *
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1197
	 *       We must therefore set the prev_il_instruction->datatype = symbol->datatype;
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1198
	 *       __before__ calling il_operand->accept(*this) !!
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1199
	 *
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1200
	 * NOTE 2: We do not need to call prev_il_instruction->accept(*this), as the object to which prev_il_instruction
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1201
	 *         is pointing to will be later narrowed by the call from the for() loop of the instruction_list_c
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1202
	 *         (or simple_instr_list_c), which iterates backwards.
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1203
	 */
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1204
	if (NULL != symbol->datatype) { // next IL instructions were able to determine the datatype this instruction should produce
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1205
		for(unsigned int i = 0; i < fake_prev_il_instruction->candidate_datatypes.size(); i++) {
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1206
			for(unsigned int j = 0; j < il_operand->candidate_datatypes.size(); j++) {
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1207
				prev_instruction_type = fake_prev_il_instruction->candidate_datatypes[i];
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1208
				operand_type = il_operand->candidate_datatypes[j];
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1209
				if (is_widening_compatible(widen_table, prev_instruction_type, operand_type, symbol->datatype, deprecated_operation)) {
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1210
					/* set the desired datatype of the previous il instruction */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1211
					set_datatype_in_prev_il_instructions(prev_instruction_type, fake_prev_il_instruction);
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1212
					/* set the datatype for the operand */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1213
					set_il_operand_datatype(il_operand, operand_type);
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1214
					
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1215
					/* NOTE: DO NOT search any further! Return immediately!
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1216
					 * Since we support SAFE*** datatypes, multiple entries in the widen_table may be compatible.
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1217
					 * If we try to set more than one distinct datatype on the same symbol, then the datatype will be set to
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1218
					 * an invalid_datatype, which is NOT what we want!
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1219
					 */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1220
					return NULL;
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1221
				}
478
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1222
			}
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1223
		}
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1224
	}
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1225
	/* We were not able to determine the required datatype, but we still give the il_operand a chance to be narrowed! */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1226
	set_il_operand_datatype(il_operand, NULL);
478
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1227
	return NULL;
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1228
}
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1229
b13feab3b918 Change setting of deprecated_operation from fill to narrow_candidate_datatypes_c.
Mario de Sousa <msousa@fe.up.pt>
parents: 472
diff changeset
  1230
443
ff4d26b7e51d Narrow IL code backwords, so as to correctly handle invocations to overloaded functions from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 441
diff changeset
  1231
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1232
838
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1233
/* Narrow IL operators whose execution is conditional on the boolean value in the accumulator.
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1234
 * Basically, narrow the JMPC, JMPCN, RETC, RETCN, CALC, and CALCN operators!
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1235
 * Also does part of the S and R operator narrowing!!!
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1236
 */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1237
void *narrow_candidate_datatypes_c::narrow_conditional_operator(symbol_c *symbol) {
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1238
	/* if the next IL instructions needs us to provide a datatype other than a BOOL or a SAFEBOOL, 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1239
	 * then we have an internal compiler error - most likely in fill_candidate_datatypes_c 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1240
	 */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1241
	// I (mario) am confident the fill/narrow algorithms are working correctly, so for now we can disable the assertions!
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1242
	//if ((NULL != symbol->datatype) && (!get_datatype_info_c::is_BOOL_compatible(symbol->datatype))) ERROR;
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1243
	//if (symbol->candidate_datatypes.size() > 2) ERROR; /* may contain, at most, a BOOL and a SAFEBOOL */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1244
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1245
	/* NOTE: If there is no IL instruction following this S, R, CALC, CALCN, JMPC, JMPCN, RETC, or RETCN instruction,
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1246
	 *       we must still provide a bool_type_name_c datatype (if possible, i.e. if it exists in the candidate datatype list).
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1247
	 *       If it is not possible, we set it to NULL
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1248
	 * 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1249
	 * NOTE: Note that this algorithm we are implementing is slightly wrong. 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1250
	 *        (a) It ignores that a SAFEBOOL may be needed instead of a BOOL datatype. 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1251
	 *        (b) It also ignores that this method gets to be called twice on the same 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1252
	 *            object (the narrow algorithm runs through the IL list twice in order to
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1253
	 *            handle forward JMPs), so the assumption that we must immediately set our
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1254
	 *            own datatype if we get called with a NULL symbol->datatype is incorrect 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1255
	 *           (it may be that the second time it is called it will be with the correct datatype!).
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1256
	 * 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1257
	 *       These two issues (a) and (b) together means that we should only really be setting our own
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1258
	 *       datatype if we are certain that the following IL instructions will never set it for us
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1259
	 *       - basically if the following IL instruction is a LD, or a JMP to a LD, or a JMP to a JMP to a LD,
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1260
	 *        etc..., or a conditional JMP whose both branches go to LD, etc...!!!
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1261
	 *       
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1262
	 *       At the moment, it seems to me that we would need to write a visitor class to do this for us!
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1263
	 *       I currently have other things on my mind at the moment, so I will leave this for later...
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1264
	 *       For the moment we just set it to BOOL, and ignore the support of SAFEBOOL!
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1265
	 */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1266
	if (NULL == symbol->datatype) set_datatype(&get_datatype_info_c::bool_type_name /* datatype*/, symbol /* symbol */);
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1267
	if (NULL == symbol->datatype) ERROR; // the BOOL is not on the candidate_datatypes! Strange... Probably a bug in fill_candidate_datatype_c
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1268
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1269
	/* set the required datatype of the previous IL instruction, i.e. a bool_type_name_c! */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1270
	set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1271
	return NULL;
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1272
}
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1273
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1274
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1275
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1276
void *narrow_candidate_datatypes_c::narrow_S_and_R_operator(symbol_c *symbol, const char *param_name, symbol_c *called_fb_declaration) {
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1277
	if (NULL != called_fb_declaration) 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1278
	  /* FB call semantics */  
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1279
	  return narrow_implicit_il_fb_call(symbol, param_name, called_fb_declaration); 
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1280
	
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1281
	/* Set/Reset semantics */  
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1282
	narrow_conditional_operator(symbol);
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1283
	/* set the datatype for the il_operand */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1284
	if ((NULL != il_operand) && (il_operand->candidate_datatypes.size() > 0))
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1285
		set_il_operand_datatype(il_operand, il_operand->candidate_datatypes[0]);
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1286
	return NULL;
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1287
}
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1288
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1289
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1290
839
99d9ef4d210b Small code cleanup (move common code to a function)
mjsousa
parents: 838
diff changeset
  1291
void *narrow_candidate_datatypes_c::narrow_store_operator(symbol_c *symbol) {
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1292
	if (symbol->candidate_datatypes.size() == 1) {
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1293
		symbol->datatype = symbol->candidate_datatypes[0];
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1294
		/* set the desired datatype of the previous il instruction */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1295
		set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1296
		/* In the case of the ST operator, we must set the datatype of the il_instruction_c object that points to this ST_operator_c ourselves,
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1297
		 * since the following il_instruction_c objects have not done it, as is normal/standard for other instructions!
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1298
		 */
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1299
		current_il_instruction->datatype = symbol->datatype;
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1300
	}
834
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
  1301
	
783ef40344dd Add support for FB call semantics of 'S' and 'R' IL operators!
mjsousa
parents: 827
diff changeset
  1302
	/* set the datatype for the operand */
836
149398f525a7 make sure all IL operands are narrowed (datatype checking algorithm)
mjsousa
parents: 834
diff changeset
  1303
	set_il_operand_datatype(il_operand, symbol->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
  1304
	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
  1305
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1306
839
99d9ef4d210b Small code cleanup (move common code to a function)
mjsousa
parents: 838
diff changeset
  1307
99d9ef4d210b Small code cleanup (move common code to a function)
mjsousa
parents: 838
diff changeset
  1308
99d9ef4d210b Small code cleanup (move common code to a function)
mjsousa
parents: 838
diff changeset
  1309
void *narrow_candidate_datatypes_c::visit(  LD_operator_c *symbol)  {return set_il_operand_datatype(il_operand, symbol->datatype);}
99d9ef4d210b Small code cleanup (move common code to a function)
mjsousa
parents: 838
diff changeset
  1310
void *narrow_candidate_datatypes_c::visit( LDN_operator_c *symbol)  {return set_il_operand_datatype(il_operand, symbol->datatype);}
99d9ef4d210b Small code cleanup (move common code to a function)
mjsousa
parents: 838
diff changeset
  1311
99d9ef4d210b Small code cleanup (move common code to a function)
mjsousa
parents: 838
diff changeset
  1312
void *narrow_candidate_datatypes_c::visit(  ST_operator_c *symbol)  {return narrow_store_operator(symbol);}
99d9ef4d210b Small code cleanup (move common code to a function)
mjsousa
parents: 838
diff changeset
  1313
void *narrow_candidate_datatypes_c::visit( STN_operator_c *symbol)  {return narrow_store_operator(symbol);}
838
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1314
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1315
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1316
/* NOTE: the standard allows syntax in which the NOT operator is followed by an optional <il_operand>
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1317
 *              NOT [<il_operand>]
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1318
 *       However, it does not define the semantic of the NOT operation when the <il_operand> is specified.
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1319
 *       We therefore consider it an error if an il_operand is specified!
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1320
 *       This error will be detected in print_datatypes_error_c!!
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1321
 */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1322
/* This operator does not change the data type, it simply inverts the bits in the ANT_BIT data types! */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1323
/* So, we merely set the desired datatype of the previous il instruction */
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1324
void *narrow_candidate_datatypes_c::visit( NOT_operator_c *symbol)  {set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction);return NULL;}
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1325
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1326
void *narrow_candidate_datatypes_c::visit(   S_operator_c *symbol)  {return narrow_S_and_R_operator   (symbol, "S",   symbol->called_fb_declaration);}
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1327
void *narrow_candidate_datatypes_c::visit(   R_operator_c *symbol)  {return narrow_S_and_R_operator   (symbol, "R",   symbol->called_fb_declaration);}
448
1bd18fc06911 Add support for semantic verification for implict FB calls in IL (e.g. PV ton_var)
Mario de Sousa <msousa@fe.up.pt>
parents: 445
diff changeset
  1328
456
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1329
void *narrow_candidate_datatypes_c::visit(  S1_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "S1",  symbol->called_fb_declaration);}
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1330
void *narrow_candidate_datatypes_c::visit(  R1_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "R1",  symbol->called_fb_declaration);}
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1331
void *narrow_candidate_datatypes_c::visit( CLK_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CLK", symbol->called_fb_declaration);}
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1332
void *narrow_candidate_datatypes_c::visit(  CU_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CU",  symbol->called_fb_declaration);}
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1333
void *narrow_candidate_datatypes_c::visit(  CD_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "CD",  symbol->called_fb_declaration);}
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1334
void *narrow_candidate_datatypes_c::visit(  PV_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "PV",  symbol->called_fb_declaration);}
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1335
void *narrow_candidate_datatypes_c::visit(  IN_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "IN",  symbol->called_fb_declaration);}
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1336
void *narrow_candidate_datatypes_c::visit(  PT_operator_c *symbol)  {return narrow_implicit_il_fb_call(symbol, "PT",  symbol->called_fb_declaration);}
ca8d98289ff9 Some small cleanups.
Mario de Sousa <msousa@fe.up.pt>
parents: 455
diff changeset
  1337
481
16f943328696 Add 'widen' tables for AND, OR and XOR operations.
Mario de Sousa <msousa@fe.up.pt>
parents: 480
diff changeset
  1338
void *narrow_candidate_datatypes_c::visit( AND_operator_c *symbol)  {return narrow_binary_operator(widen_AND_table, symbol);}
16f943328696 Add 'widen' tables for AND, OR and XOR operations.
Mario de Sousa <msousa@fe.up.pt>
parents: 480
diff changeset
  1339
void *narrow_candidate_datatypes_c::visit(  OR_operator_c *symbol)  {return narrow_binary_operator( widen_OR_table, symbol);}
16f943328696 Add 'widen' tables for AND, OR and XOR operations.
Mario de Sousa <msousa@fe.up.pt>
parents: 480
diff changeset
  1340
void *narrow_candidate_datatypes_c::visit( XOR_operator_c *symbol)  {return narrow_binary_operator(widen_XOR_table, symbol);}
483
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 481
diff changeset
  1341
void *narrow_candidate_datatypes_c::visit(ANDN_operator_c *symbol)  {return narrow_binary_operator(widen_AND_table, symbol);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 481
diff changeset
  1342
void *narrow_candidate_datatypes_c::visit( ORN_operator_c *symbol)  {return narrow_binary_operator( widen_OR_table, symbol);}
7f839fb100c1 Cleaning up XORN, ANDN, and ORN operator code.
Mario de Sousa <msousa@fe.up.pt>
parents: 481
diff changeset
  1343
void *narrow_candidate_datatypes_c::visit(XORN_operator_c *symbol)  {return narrow_binary_operator(widen_XOR_table, symbol);}
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1344
void *narrow_candidate_datatypes_c::visit( ADD_operator_c *symbol)  {return narrow_binary_operator(widen_ADD_table, symbol, &(symbol->deprecated_operation));}
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1345
void *narrow_candidate_datatypes_c::visit( SUB_operator_c *symbol)  {return narrow_binary_operator(widen_SUB_table, symbol, &(symbol->deprecated_operation));}
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1346
void *narrow_candidate_datatypes_c::visit( MUL_operator_c *symbol)  {return narrow_binary_operator(widen_MUL_table, symbol, &(symbol->deprecated_operation));}
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1347
void *narrow_candidate_datatypes_c::visit( DIV_operator_c *symbol)  {return narrow_binary_operator(widen_DIV_table, symbol, &(symbol->deprecated_operation));}
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1348
void *narrow_candidate_datatypes_c::visit( MOD_operator_c *symbol)  {return narrow_binary_operator(widen_MOD_table, symbol);}
484
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1349
void *narrow_candidate_datatypes_c::visit(  GT_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1350
void *narrow_candidate_datatypes_c::visit(  GE_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1351
void *narrow_candidate_datatypes_c::visit(  EQ_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1352
void *narrow_candidate_datatypes_c::visit(  LT_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1353
void *narrow_candidate_datatypes_c::visit(  LE_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, symbol);}
f78750994a82 Clean code for comparison operations & operators.
Mario de Sousa <msousa@fe.up.pt>
parents: 483
diff changeset
  1354
void *narrow_candidate_datatypes_c::visit(  NE_operator_c *symbol)  {return narrow_binary_operator(widen_CMP_table, 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: 445
diff changeset
  1355
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
  1356
838
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1357
/* visitors to CAL_operator_c, CALC_operator_c and CALCN_operator_c are called from visit(il_fb_call_c *) {symbol->il_call_operator->accept(*this)} */
487
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1358
/* NOTE: The CAL, JMP and RET instructions simply set the desired datatype of the previous il instruction since they do not change the value in the current/default IL variable */
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1359
void *narrow_candidate_datatypes_c::visit(  CAL_operator_c *symbol) {set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction); return NULL;}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1360
void *narrow_candidate_datatypes_c::visit(  RET_operator_c *symbol) {set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction); return NULL;}
1619b2fe03e1 Clean up the code.
Mario de Sousa <msousa@fe.up.pt>
parents: 484
diff changeset
  1361
void *narrow_candidate_datatypes_c::visit(  JMP_operator_c *symbol) {set_datatype_in_prev_il_instructions(symbol->datatype, fake_prev_il_instruction); return NULL;}
838
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1362
void *narrow_candidate_datatypes_c::visit( CALC_operator_c *symbol) {return narrow_conditional_operator(symbol);}
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1363
void *narrow_candidate_datatypes_c::visit(CALCN_operator_c *symbol) {return narrow_conditional_operator(symbol);}
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1364
void *narrow_candidate_datatypes_c::visit( RETC_operator_c *symbol) {return narrow_conditional_operator(symbol);}
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1365
void *narrow_candidate_datatypes_c::visit(RETCN_operator_c *symbol) {return narrow_conditional_operator(symbol);}
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1366
void *narrow_candidate_datatypes_c::visit( JMPC_operator_c *symbol) {return narrow_conditional_operator(symbol);}
13ea7c080018 Fix datatype analysis of conditional IL operators (CALC, CALCN, RETC, RETCN, JMPC, JMPCN, S and R)
mjsousa
parents: 836
diff changeset
  1367
void *narrow_candidate_datatypes_c::visit(JMPCN_operator_c *symbol) {return narrow_conditional_operator(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
  1368
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1369
/* 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
  1370
// 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
  1371
/* 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
  1372
// 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
  1373
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1374
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1375
/***************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1376
/* 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
  1377
/***************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1378
/***********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1379
/* 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
  1380
/***********************/
873
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1381
/* SYM_REF1(ref_expression_c, exp)  --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1382
void *narrow_candidate_datatypes_c::visit(  ref_expression_c  *symbol) {
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1383
  if (symbol->exp->candidate_datatypes.size() > 0) {
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1384
    symbol->exp->datatype = symbol->exp->candidate_datatypes[0]; /* just use the first possible datatype */
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1385
  }
910
a0518971127d Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
mjsousa
parents: 909
diff changeset
  1386
  symbol->exp->accept(*this);
873
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1387
  return NULL;
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1388
}
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1389
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1390
dea39ef02847 Add limited support for the REF() operator (defined in v3 of IEC 61131-3)
mjsousa
parents: 854
diff changeset
  1391
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1392
/* allow_enums is FALSE by default!!
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1393
 * deprecated_operation is NULL by default!!
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1394
 * if (allow_enums) then consider that we are ectually processing an equ_expression or notequ_expression, where two enums of the same data type may also be legally compared 
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1395
 *  e.g.      symbol := l_expr == r_expr              
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1396
 *            symbol := l_expr != r_expr
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1397
 *  In the above situation it is a legal operation when (l_expr.datatype == r_expr.datatype) && is_enumerated(r/l_expr.datatype) && is_bool(symbol.datatype)
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1398
 */
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1399
void *narrow_candidate_datatypes_c::narrow_binary_expression(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr, bool *deprecated_operation, bool allow_enums) {
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1400
	symbol_c *l_type, *r_type;
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1401
	int count = 0;
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1402
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1403
	if (NULL != deprecated_operation)
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1404
		*deprecated_operation = false;
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1405
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1406
	for(unsigned int i = 0; i < l_expr->candidate_datatypes.size(); i++) {
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1407
		for(unsigned int j = 0; j < r_expr->candidate_datatypes.size(); j++) {
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1408
			/* test widening compatibility */
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1409
			l_type = l_expr->candidate_datatypes[i];
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1410
			r_type = r_expr->candidate_datatypes[j];
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1411
			if        (is_widening_compatible(widen_table, l_type, r_type, symbol->datatype, deprecated_operation)) {
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1412
				l_expr->datatype = l_type;
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1413
				r_expr->datatype = r_type;
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1414
				count ++;
919
8da635655f37 Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents: 910
diff changeset
  1415
			} else if (   /* handle the special case of enumerations */
8da635655f37 Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents: 910
diff changeset
  1416
			              (get_datatype_info_c::is_BOOL_compatible(symbol->datatype) && get_datatype_info_c::is_enumerated(l_type) && (l_type == r_type))
8da635655f37 Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents: 910
diff changeset
  1417
			              /* handle the special case of comparison between REF_TO datatypes */
8da635655f37 Add support for the 'NULL' keyword, defined in version 3 of IEC 61131-3.
mjsousa
parents: 910
diff changeset
  1418
			           || (get_datatype_info_c::is_BOOL_compatible(symbol->datatype) && get_datatype_info_c::is_ref_to    (l_type) && get_datatype_info_c::is_type_equal(l_type, r_type))) {
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1419
				if (NULL != deprecated_operation)  *deprecated_operation = false;
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1420
				l_expr->datatype = l_type;
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1421
				r_expr->datatype = r_type;
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1422
				count ++;
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1423
			}
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1424
			  
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1425
		}
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1426
	}
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1427
// 	if (count > 1) ERROR; /* Since we also support SAFE data types, this assertion is not necessarily always tru! */
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 675
diff changeset
  1428
	if (get_datatype_info_c::is_type_valid(symbol->datatype) && (count <= 0)) ERROR;
480
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1429
	
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1430
	l_expr->accept(*this);
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1431
	r_expr->accept(*this);
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1432
	return NULL;
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1433
}
8a58d7b8b26c Add MOD widening table, and some code clean-ups.
Mario de Sousa <msousa@fe.up.pt>
parents: 478
diff changeset
  1434
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
  1435
652
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1436
void *narrow_candidate_datatypes_c::narrow_equality_comparison(const struct widen_entry widen_table[], symbol_c *symbol, symbol_c *l_expr, symbol_c *r_expr, bool *deprecated_operation) {
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1437
	return narrow_binary_expression(widen_table, symbol, l_expr, r_expr, deprecated_operation, true);
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1438
}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1439
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1440
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1441
void *narrow_candidate_datatypes_c::visit(    or_expression_c *symbol) {return narrow_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: 552
diff changeset
  1442
void *narrow_candidate_datatypes_c::visit(   xor_expression_c *symbol) {return narrow_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: 552
diff changeset
  1443
void *narrow_candidate_datatypes_c::visit(   and_expression_c *symbol) {return narrow_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: 552
diff changeset
  1444
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1445
void *narrow_candidate_datatypes_c::visit(   equ_expression_c *symbol) {return narrow_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: 552
diff changeset
  1446
void *narrow_candidate_datatypes_c::visit(notequ_expression_c *symbol) {return narrow_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: 552
diff changeset
  1447
void *narrow_candidate_datatypes_c::visit(    lt_expression_c *symbol) {return narrow_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: 552
diff changeset
  1448
void *narrow_candidate_datatypes_c::visit(    gt_expression_c *symbol) {return narrow_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: 552
diff changeset
  1449
void *narrow_candidate_datatypes_c::visit(    le_expression_c *symbol) {return narrow_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: 552
diff changeset
  1450
void *narrow_candidate_datatypes_c::visit(    ge_expression_c *symbol) {return narrow_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: 552
diff changeset
  1451
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1452
void *narrow_candidate_datatypes_c::visit(   add_expression_c *symbol) {return narrow_binary_expression  (widen_ADD_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1453
void *narrow_candidate_datatypes_c::visit(   sub_expression_c *symbol) {return narrow_binary_expression  (widen_SUB_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1454
void *narrow_candidate_datatypes_c::visit(   mul_expression_c *symbol) {return narrow_binary_expression  (widen_MUL_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1455
void *narrow_candidate_datatypes_c::visit(   div_expression_c *symbol) {return narrow_binary_expression  (widen_DIV_table, symbol, symbol->l_exp, symbol->r_exp, &symbol->deprecated_operation);}
7fe1533d2260 Start adding support for data type checking of enums.
Mario de Sousa <msousa@fe.up.pt>
parents: 552
diff changeset
  1456
void *narrow_candidate_datatypes_c::visit(   mod_expression_c *symbol) {return narrow_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: 552
diff changeset
  1457
void *narrow_candidate_datatypes_c::visit( power_expression_c *symbol) {return narrow_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
  1458
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *narrow_candidate_datatypes_c::visit(neg_expression_c *symbol) {
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1461
	symbol->exp->datatype = symbol->datatype;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1462
	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
  1463
	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
  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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *narrow_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
  1468
	symbol->exp->datatype = symbol->datatype;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1469
	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
  1470
	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
  1471
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1472
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1473
438
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1474
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1475
/* NOTE: The parameter 'called_function_declaration', 'extensible_param_count' and 'candidate_functions' 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: 428
diff changeset
  1476
/*    formal_param_list -> may be NULL ! */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1477
/* nonformal_param_list -> may be NULL ! */
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1478
// SYM_REF3(function_invocation_c, function_name, formal_param_list, nonformal_param_list, symbol_c *called_function_declaration; int extensible_param_count; std::vector <symbol_c *> candidate_functions;)
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1479
void *narrow_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: 428
diff changeset
  1480
	generic_function_call_t fcall_param = {
441
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1481
		/* fcall_param.function_name               = */ symbol->function_name,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1482
		/* fcall_param.nonformal_operand_list      = */ symbol->nonformal_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1483
		/* fcall_param.formal_operand_list         = */ symbol->formal_param_list,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1484
		/* enum {POU_FB, POU_function} POU_type    = */ generic_function_call_t::POU_function,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1485
		/* fcall_param.candidate_functions         = */ symbol->candidate_functions,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1486
		/* fcall_param.called_function_declaration = */ symbol->called_function_declaration,
e8de43eefcc5 Add printing of semantic errors when calling FB from IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 439
diff changeset
  1487
		/* 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: 428
diff changeset
  1488
	};
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1489
  
744b125d911e Add support for semantic verification of function calls in IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 428
diff changeset
  1490
	narrow_function_invocation(symbol, fcall_param);
417
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1491
	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
  1492
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1493
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1494
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1495
/* 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
  1496
/********************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1497
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
  1501
/*********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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 *narrow_candidate_datatypes_c::visit(assignment_statement_c *symbol) {
910
a0518971127d Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
mjsousa
parents: 909
diff changeset
  1504
	if (symbol->candidate_datatypes.size() == 1) {
a0518971127d Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
mjsousa
parents: 909
diff changeset
  1505
		symbol->datatype = symbol->candidate_datatypes[0];
a0518971127d Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
mjsousa
parents: 909
diff changeset
  1506
		symbol->l_exp->datatype = symbol->datatype;
a0518971127d Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
mjsousa
parents: 909
diff changeset
  1507
		symbol->r_exp->datatype = symbol->datatype;
a0518971127d Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
mjsousa
parents: 909
diff changeset
  1508
	}
a0518971127d Narrow array subscripts correctly, even in the presence of other datatype errors (so we do not generate error messages for array subscripts that do not contain errors).
mjsousa
parents: 909
diff changeset
  1509
	/* give the chance of any expressions inside array subscripts to be narrowed correctly */
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
  1510
	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
  1511
	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
  1512
	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
  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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/*****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* B 3.2.2 Subprogram Control 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
  1518
/*****************************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
423
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1520
void *narrow_candidate_datatypes_c::visit(fb_invocation_c *symbol) {
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: 423
diff changeset
  1521
	/* Note: We do not use the symbol->called_fb_declaration value (set in fill_candidate_datatypes_c)
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: 423
diff changeset
  1522
	 *       because we try to identify any other datatype errors in the expressions used in the 
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: 423
diff changeset
  1523
	 *       parameters to the FB call (e.g.  fb_var(var1 * 56 + func(var * 43)) )
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: 423
diff changeset
  1524
	 *       even it the call to the FB is invalid. 
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: 423
diff changeset
  1525
	 *       This makes sense because it may be errors in those expressions which are
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: 423
diff changeset
  1526
	 *       making this an invalid call, so it makes sense to point them out to the user!
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: 423
diff changeset
  1527
	 */
423
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1528
	symbol_c *fb_decl = search_varfb_instance_type->get_basetype_decl(symbol->fb_name);
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: 423
diff changeset
  1529
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: 423
diff changeset
  1530
	/* Although a call to a non-declared FB is a semantic error, this is currently caught by stage 2! */
423
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1531
	if (NULL == fb_decl) ERROR;
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1532
	if (NULL != symbol->nonformal_param_list)  narrow_nonformal_call(symbol, fb_decl);
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1533
	if (NULL != symbol->   formal_param_list)     narrow_formal_call(symbol, fb_decl);
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1534
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1535
	return NULL;
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1536
}
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1537
f4a2d400ddbd Adding support for semantic verification of FB calls in ST.
Mario de Sousa <msousa@fe.up.pt>
parents: 421
diff changeset
  1538
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
  1539
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
  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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *narrow_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
  1544
	for(unsigned int i = 0; i < symbol->expression->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
  1545
		if (get_datatype_info_c::is_BOOL_compatible(symbol->expression->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
  1546
			symbol->expression->datatype = symbol->expression->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
  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
	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
  1549
	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
  1550
		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
  1551
	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
  1552
		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
  1553
	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
  1554
		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
  1555
	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
  1556
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
void *narrow_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
  1560
	for (unsigned int i = 0; i < symbol->expression->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
  1561
		if (get_datatype_info_c::is_BOOL_compatible(symbol->expression->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
  1562
			symbol->expression->datatype = symbol->expression->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
  1563
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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->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
  1565
	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
  1566
		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
  1567
	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
  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
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write 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
/* 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
  1571
// 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
  1572
void *narrow_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
  1573
	for (unsigned int i = 0; i < symbol->expression->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
  1574
		if ((get_datatype_info_c::is_ANY_INT(symbol->expression->candidate_datatypes[i]))
854
13d0b67de111 Code cleanup: move datatype analysis to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 843
diff changeset
  1575
				 || (get_datatype_info_c::is_enumerated(symbol->expression->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
  1576
			symbol->expression->datatype = symbol->expression->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
  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
	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
  1579
	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
  1580
		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
  1581
	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
  1582
		symbol->case_element_list->datatype = symbol->expression->datatype;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1583
		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
  1584
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1585
	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
  1586
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1587
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1588
/* 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
  1589
// 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
  1590
void *narrow_candidate_datatypes_c::visit(case_element_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
  1591
	for (int i = 0; i < symbol->n; 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
  1592
		symbol->elements[i]->datatype = symbol->datatype;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1593
		symbol->elements[i]->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
  1594
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1595
	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
  1596
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1597
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1598
/*  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
  1599
// 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
  1600
void *narrow_candidate_datatypes_c::visit(case_element_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
  1601
	symbol->case_list->datatype = symbol->datatype;
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1602
	symbol->case_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
  1603
	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
  1604
	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
  1605
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1606
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1607
// 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
  1608
void *narrow_candidate_datatypes_c::visit(case_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
  1609
	for (int i = 0; i < symbol->n; 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
  1610
		for (unsigned int k = 0; k < symbol->elements[i]->candidate_datatypes.size(); k++) {
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 675
diff changeset
  1611
			if (get_datatype_info_c::is_type_equal(symbol->datatype, symbol->elements[i]->candidate_datatypes[k]))
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
  1612
				symbol->elements[i]->datatype = symbol->elements[i]->candidate_datatypes[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
  1613
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1614
		/* NOTE: this may be an integer, a subrange_c, or a enumerated 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
  1615
		symbol->elements[i]->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
  1616
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1617
	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
  1618
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1619
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1620
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1621
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1622
/* 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
  1623
/********************************/
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1624
void *narrow_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
  1625
	/* Control variable */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1626
	for(unsigned int i = 0; i < symbol->control_variable->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
  1627
		if (get_datatype_info_c::is_ANY_INT(symbol->control_variable->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
  1628
			symbol->control_variable->datatype = symbol->control_variable->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
  1629
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1630
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1631
	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
  1632
	/* BEG expression */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1633
	for(unsigned int i = 0; i < symbol->beg_expression->candidate_datatypes.size(); i++) {
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 675
diff changeset
  1634
		if (get_datatype_info_c::is_type_equal(symbol->control_variable->datatype,symbol->beg_expression->candidate_datatypes[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
  1635
				get_datatype_info_c::is_ANY_INT(symbol->beg_expression->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
  1636
			symbol->beg_expression->datatype = symbol->beg_expression->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
  1637
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1638
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1639
	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
  1640
	/* END expression */
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1641
	for(unsigned int i = 0; i < symbol->end_expression->candidate_datatypes.size(); i++) {
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 675
diff changeset
  1642
		if (get_datatype_info_c::is_type_equal(symbol->control_variable->datatype,symbol->end_expression->candidate_datatypes[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
  1643
				get_datatype_info_c::is_ANY_INT(symbol->end_expression->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
  1644
			symbol->end_expression->datatype = symbol->end_expression->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
  1645
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1646
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1647
	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
  1648
	/* 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
  1649
	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
  1650
		for(unsigned int i = 0; i < symbol->by_expression->candidate_datatypes.size(); i++) {
676
ca4f17211251 Move is_datatype_valid/equal() to get_datatype_info_c
Mario de Sousa <msousa@fe.up.pt>
parents: 675
diff changeset
  1651
			if (get_datatype_info_c::is_type_equal(symbol->control_variable->datatype,symbol->by_expression->candidate_datatypes[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
  1652
					get_datatype_info_c::is_ANY_INT(symbol->by_expression->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
  1653
				symbol->by_expression->datatype = symbol->by_expression->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
  1654
			}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1655
		}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1656
		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
  1657
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1658
	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
  1659
		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
  1660
	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
  1661
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1662
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1663
void *narrow_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
  1664
	for (unsigned int i = 0; i < symbol->expression->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
  1665
		if(get_datatype_info_c::is_BOOL(symbol->expression->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
  1666
			symbol->expression->datatype = symbol->expression->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
  1667
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1668
	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
  1669
	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
  1670
		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
  1671
	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
  1672
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1673
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1674
void *narrow_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
  1675
	for (unsigned int i = 0; i < symbol->expression->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
  1676
		if(get_datatype_info_c::is_BOOL(symbol->expression->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
  1677
			symbol->expression->datatype = symbol->expression->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
  1678
	}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1679
	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
  1680
	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
  1681
		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
  1682
	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
  1683
}
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1684
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1685
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1686
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1687
d48f53715f77 Re-write of stage3 code (done by Manuele and I), re-write of search_varfb_instance_type_c (done by myself), and several other bug fixes.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
  1688