stage3/forced_narrow_candidate_datatypes.cc
author Mario de Sousa <msousa@fe.up.pt>
Wed, 26 Dec 2018 11:56:14 +0000
changeset 1082 903e2782e405
parent 1054 57c08195c962
permissions -rw-r--r--
fix bug introduced in previous commit (force literals to unsigned log long)
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     1
/*
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     3
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     4
 *  Copyright (C) 2012  Mario de Sousa (msousa@fe.up.pt)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     5
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     8
 *  the Free Software Foundation, either version 3 of the License, or
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     9
 *  (at your option) any later version.
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    10
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    14
 *  GNU General Public License for more details.
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    15
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    18
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    19
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    20
 * This code is made available on the understanding that it will not be
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    21
 * used in safety-critical situations without a full and competent review.
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    22
 */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    23
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    24
/*
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    25
 * An IEC 61131-3 compiler.
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    26
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    27
 * Based on the
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    28
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    29
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    30
 */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    31
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    32
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    33
/*
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    34
 *  Data type analysis of IL code may leave some IL instructions with an undefined datatype.
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    35
 *  This visitor will set the datatype for all these symbols, so that all symbols have a well 
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    36
 *  defined datatype when we reach stage4.
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    37
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    38
 *  Example:
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    39
 * =========
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    40
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    41
 *  VAR 
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    42
 *     N   : INT := 99 ;    
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    43
 *     tonv: TON;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    44
 *     byte_var: BYTE;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    45
 *     tonv : TON;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    46
 *     a : BYTE;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    47
 *     t : time;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    48
 *     tod1: tod;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    49
 *  END_VAR
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    50
 *  
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    51
 * (0) --> Data type before executing forced_narrow_candidate_datatypes_c
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    52
 * (1) --> Data type after executing 1st pass of forced_narrow_candidate_datatypes_c
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    53
 * (2) --> Data type after executing 2nd pass of forced_narrow_candidate_datatypes_c
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    54
 * 
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    55
 * --- --> NULL (undefined datatype)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    56
 * *** --> invalid_type_name_c (invalid datatype)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    57
 *
681
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    58
 * (0)   PASS1   (1)    PASS2   (2)
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    59
 *      
681
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    60
 * ---     (e)   ***            ***       CAL tonv (                          
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    61
 *                                               PT := T#1s                   
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    62
 *                                            )                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    63
 * ---     (e)   ***            ***       JMP l4                              
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    64
 *
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    65
 * ---     (e)   sint           sint  l0: LD  1                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    66
 * ---     (e)   sint           sint      ADD 2                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    67
 * ---  (c)      sint           sint      CAL tonv (                          
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    68
 *                                            PT := T#1s                      
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    69
 *                                            )                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    70
 *                                                                            
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    71
 * ---     (e)   sint           sint      LD  45                              
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    72
 * ---  (c)      sint           sint      ADD 45                              
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    73
 *
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    74
 *
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    75
 * ---     (e)   sint           sint      LD  3                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    76
 * ---     (e)   sint           sint  l1:                                     
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    77
 * ---  (c)      sint           sint  l2: ADD 4                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    78
 * int           int            int       LD  5                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    79
 * int           int            int       ST  n                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    80
 * int           int            int       JMP l3                              
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    81
 *                                                                            
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    82
 * ---  (d)      ---      (e)   sint      LD  5                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    83
 * ---  (d)      ---      (e)   sint      SUB 6                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    84
 * ---  (d)(e)   sint           sint      JMP l1                              
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    85
 *
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    86
 * ---     (e)   bool           bool      LD  FALSE                           
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    87
 * ---     (e)   bool           bool      NOT                                 
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    88
 * ---  (b)      bool           bool      RET                                 
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    89
 *
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    90
 * int           int            int   l3:                                     
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    91
 * int           int            int       ST  n                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    92
 * ---  (b)      int            int       RET                                 
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    93
 *
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    94
 * ---     (e)   ***            ***   l4:                                     
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    95
 * ---     (e)   ***            ***       CAL tonv (                          
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    96
 *                                               PT := T#1s                   
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    97
 *                                            )                               
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    98
 * ---  (a)      ***            ***       JMP l0                              
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
    99
 * ---  (b)      byte           byte      LD  88                              
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   100
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   101
 *
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   102
 *   
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   103
 */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   104
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   105
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   106
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   107
#include "forced_narrow_candidate_datatypes.hh"
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   108
#include "datatype_functions.hh"
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   109
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   110
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   111
/* set to 1 to see debug info during execution */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   112
static int debug = 0;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   113
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   114
forced_narrow_candidate_datatypes_c::forced_narrow_candidate_datatypes_c(symbol_c *ignore) 
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   115
 :narrow_candidate_datatypes_c(ignore) {
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   116
}
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   117
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   118
forced_narrow_candidate_datatypes_c::~forced_narrow_candidate_datatypes_c(void) {
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   119
}
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   120
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   121
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   122
1054
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   123
void forced_narrow_candidate_datatypes_c::set_datatype_in_prev_il_instructions(symbol_c *datatype, il_instruction_c *symbol) {
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   124
	if (NULL == symbol) ERROR;
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   125
	/* In the forced_narrow_candidate_datatypes algorithm, we do NOT set any datatypes to invalid_type_name_c
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   126
	 * Any IL instructions that really are of an invalid_type_name_c (because the IL code is buggy?) have already
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   127
	 * been set by the standard narrow_candidate_datatypes algorithm.
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   128
	 * 
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   129
	 * Remember too that valid IL code may also have some IL instructions correctly set to invalid_type_name_c, especially
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   130
	 * in cases where the data in the accumulator will not be used in the current IL instruction
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   131
	 * For example:
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   132
	 *        LD   bool_var
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   133
	 *        JMPC label1
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   134
	 *        LD 34
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   135
	 *        ST int_var
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   136
	 * lable1:            <----  This IL instruction_c (with NULL symbol->il_instruction) has invalid_type_name_c datatype!!
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   137
	 *        LD T#3s              And yet, the code is legal!!!
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   138
	 *        ST time_var
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   139
	 */ 
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   140
	if (!get_datatype_info_c::is_type_valid(datatype)) return;
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   141
	// Call the 'original' version of the set_datatype_in_prev_il_instructions() function, from narrow_candidate_datatypes_c
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   142
	return narrow_candidate_datatypes_c::set_datatype_in_prev_il_instructions(datatype, symbol);
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   143
}
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   144
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   145
57c08195c962 Fix bug in datatype narrowing algorithm affecting IL code.
Mario de Sousa <msousa@fe.up.pt>
parents: 1041
diff changeset
   146
691
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   147
void forced_narrow_candidate_datatypes_c::forced_narrow_il_instruction(symbol_c *symbol, std::vector <symbol_c *> &next_il_instruction) {
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   148
  if (NULL == symbol->datatype) {
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   149
    if (symbol->candidate_datatypes.empty()) {
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: 691
diff changeset
   150
      symbol->datatype = &(get_datatype_info_c::invalid_type_name); // This will occur in the situations (a) in the above example
691
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   151
      // return NULL; // No need to return control to the visit() method of the base class... But we do so, just to be safe (called at the end of this function)!
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   152
    } else {
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   153
      if (next_il_instruction.empty()) {
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   154
        symbol->datatype = symbol->candidate_datatypes[0]; // This will occur in the situations (b) in the above example
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   155
      } else {
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   156
        symbol_c *next_datatype = NULL;
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   157
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   158
        /* find the datatype of the following IL instructions (they should all be identical by now, but we don't have an assertion checking for this. */
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   159
        for (unsigned int i=0; i < next_il_instruction.size(); i++)
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   160
          if (NULL != next_il_instruction[i]->datatype)
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   161
            next_datatype = next_il_instruction[i]->datatype;
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   162
        if (get_datatype_info_c::is_type_valid(next_datatype)) {
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   163
          //  This will occur in the situations (c) in the above example
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   164
          symbol->datatype = symbol->candidate_datatypes[0]; 
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   165
        } else {
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   166
          //  This will occur in the situations (d) in the above example
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   167
          // it is not possible to determine the exact situation in the current pass, so we can't do anything just yet. Leave it for the next time around!
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   168
        }
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   169
      }
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   170
    }
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   171
  }
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   172
}
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   173
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   174
681
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   175
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   176
/****************************************/
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   177
/* B.2 - Language IL (Instruction List) */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   178
/****************************************/
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   179
/***********************************/
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   180
/* B 2.1 Instructions and Operands */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   181
/***********************************/
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   182
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   183
/*| instruction_list il_instruction */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   184
// SYM_LIST(instruction_list_c)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   185
void *forced_narrow_candidate_datatypes_c::visit(instruction_list_c *symbol) {
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   186
  for(int j = 0; j < 2; j++) {
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   187
    for(int i = symbol->n-1; i >= 0; i--) {
1041
56ebe2a31b5b Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
   188
      symbol->get_element(i)->accept(*this);
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   189
    }
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   190
  }
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   191
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   192
  /* Assert that this algorithm managed to remove all NULL datatypes! */
684
0e417d42cf6a Comment out invalid assertion.
Mario de Sousa <msousa@fe.up.pt>
parents: 681
diff changeset
   193
  /* NOTE: The forced_narrow_candidate_datatypes_c assumes that the original IEC 61131-3 source code does not have any bugs!
0e417d42cf6a Comment out invalid assertion.
Mario de Sousa <msousa@fe.up.pt>
parents: 681
diff changeset
   194
   *       This means we cannot run this assertion here, as the compiler will bork in the presence of bug in the code being compiled! Not good!!
0e417d42cf6a Comment out invalid assertion.
Mario de Sousa <msousa@fe.up.pt>
parents: 681
diff changeset
   195
   */
0e417d42cf6a Comment out invalid assertion.
Mario de Sousa <msousa@fe.up.pt>
parents: 681
diff changeset
   196
  /*
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   197
  for(int i = symbol->n-1; i >= 0; i--) {
1041
56ebe2a31b5b Access elements[] in list_c through a new get_element() method.
Mario de Sousa <msousa@fe.up.pt>
parents: 693
diff changeset
   198
    if (NULL == symbol->get_element(i)->datatype)
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   199
      ERROR;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   200
  }
684
0e417d42cf6a Comment out invalid assertion.
Mario de Sousa <msousa@fe.up.pt>
parents: 681
diff changeset
   201
  */
686
9b87606d4c07 Fix processing of TIME literals (submited by Andreas)
Mario de Sousa <msousa@fe.up.pt>
parents: 684
diff changeset
   202
  
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   203
  return NULL;
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   204
}
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   205
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   206
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   207
  
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   208
/* | label ':' [il_incomplete_instruction] eol_list */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   209
// SYM_REF2(il_instruction_c, label, il_instruction)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   210
// void *visit(instruction_list_c *symbol);
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   211
void *forced_narrow_candidate_datatypes_c::visit(il_instruction_c *symbol) {
691
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   212
  forced_narrow_il_instruction(symbol, symbol->next_il_instruction);
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   213
  
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   214
  /* return control to the visit() method of the base class! */
691
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   215
  return narrow_candidate_datatypes_c::visit(symbol);  //  This handles the situations (e) in the above example
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   216
}
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   217
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   218
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   219
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   220
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   221
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   222
/* | il_simple_operator [il_operand] */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   223
// SYM_REF2(il_simple_operation_c, il_simple_operator, il_operand)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   224
// void *forced_narrow_candidate_datatypes_c::visit(il_simple_operation_c *symbol)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   225
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   226
/* | function_name [il_operand_list] */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   227
/* NOTE: The parameters 'called_function_declaration' and 'extensible_param_count' are used to pass data between the stage 3 and stage 4. */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   228
// SYM_REF2(il_function_call_c, function_name, il_operand_list, symbol_c *called_function_declaration; int extensible_param_count;)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   229
// void *forced_narrow_candidate_datatypes_c::visit(il_function_call_c *symbol) 
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   230
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   231
/* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   232
// SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list);
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   233
// void *forced_narrow_candidate_datatypes_c::visit(il_expression_c *symbol)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   234
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   235
/*  il_jump_operator label */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   236
// SYM_REF2(il_jump_operation_c, il_jump_operator, label)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   237
// void *forced_narrow_candidate_datatypes_c::visit(il_jump_operation_c *symbol)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   238
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   239
/*   il_call_operator prev_declared_fb_name
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   240
 * | il_call_operator prev_declared_fb_name '(' ')'
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   241
 * | il_call_operator prev_declared_fb_name '(' eol_list ')'
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   242
 * | il_call_operator prev_declared_fb_name '(' il_operand_list ')'
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   243
 * | il_call_operator prev_declared_fb_name '(' eol_list il_param_list ')'
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   244
 */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   245
/* NOTE: The parameter 'called_fb_declaration'is used to pass data between stage 3 and stage4 (although currently it is not used in stage 4 */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   246
// SYM_REF4(il_fb_call_c, il_call_operator, fb_name, il_operand_list, il_param_list, symbol_c *called_fb_declaration)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   247
// void *forced_narrow_candidate_datatypes_c::visit(il_fb_call_c *symbol)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   248
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   249
/* | function_name '(' eol_list [il_param_list] ')' */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   250
/* NOTE: The parameter 'called_function_declaration' is used to pass data between the stage 3 and stage 4. */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   251
// SYM_REF2(il_formal_funct_call_c, function_name, il_param_list, symbol_c *called_function_declaration; int extensible_param_count;)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   252
// void *forced_narrow_candidate_datatypes_c::visit(il_formal_funct_call_c *symbol)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   253
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   254
// void *visit(il_operand_list_c *symbol);
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   255
// void *forced_narrow_candidate_datatypes_c::visit(simple_instr_list_c *symbol)
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   256
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   257
// SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;)
691
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   258
void *forced_narrow_candidate_datatypes_c::visit(il_simple_instruction_c*symbol) {
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   259
  forced_narrow_il_instruction(symbol, symbol->next_il_instruction);
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   260
  
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   261
  /* return control to the visit() method of the base class! */
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   262
  return narrow_candidate_datatypes_c::visit(symbol);  //  This handle the situations (e) in the above example
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   263
}
958454e9e40f Also force_narrow IL instructions inside IL expressions, i.e. inside parenthesis.
Mario de Sousa <msousa@fe.up.pt>
parents: 688
diff changeset
   264
677
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   265
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   266
/*
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   267
    void *visit(il_param_list_c *symbol);
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   268
    void *visit(il_param_assignment_c *symbol);
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   269
    void *visit(il_param_out_assignment_c *symbol);
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   270
 */
740da3255d9d Remove all remaining NULL (undefined) datatypes from IL code.
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   271
681
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   272
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   273
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   274
/***************************************/
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   275
/* B.3 - Language ST (Structured Text) */
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   276
/***************************************/
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   277
// SYM_LIST(statement_list_c)
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   278
/* The normal narrow_candidate_datatypes_c algorithm does not leave any symbol, in an ST code, with an undefined datatype.
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   279
 * There is therefore no need to re-run the narrow algorithm here, so we overide the narrow_candidate_datatypes_c visitor,
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   280
 * and simply bug out!
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   281
 */
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   282
void *forced_narrow_candidate_datatypes_c::visit(statement_list_c *symbol) {return NULL;}
e837adad2437 Do not repeat narrow algorithm for ST code, and better comments.
Mario de Sousa <msousa@fe.up.pt>
parents: 679
diff changeset
   283